I’m pretty new to Unity and Programming as a whole, recently I’ve been trying to practice with simple animation (just switching idle to walk). I’ve gotten it to work in js but I’d prefer all my code to be in C#, so I’m curious how it would look.
In Java:
#pragma strict
var speed : float = 5f;
var anim : Animator;
function Start () {
anim = gameObject.GetComponent(Animator);
}
function Update () {
if(Input.GetKeyDown(KeyCode.T))
{
anim.SetFloat("Trigger",1); //Starts walk animation
}
else
{
anim.SetFloat("Trigger",0); //Otherwise loop idle animation
}
}
What I tried:
using UnityEngine;
using System.Collections;
public class Testing : MonoBehaviour {
private float speed = 5f;
private Animator anim;
void Start () {
anim = gameObject.GetComponent(Animator);
}
void Update () {
if(Input.GetKeyDown(KeyCode.T))
{
anim.SetFloat("Trigger",1); //Starts walk animation
}
else
{
anim.SetFloat("Trigger",0); //Otherwise loop idle animation
}
}
}
It’s not working, but again I’m just starting to learn to program. What should it look like in C#?