I am an art student and have no idea how to do computers good. My professor and I have been trying to get my animations to be triggered by key presses. I have a character who needs to be able to shift from their idle animation to their walking animation. I am also adding an additional animation where my character will hop into the air and hover. I would love for this to be a trigger that you hold the SpaceBar down to hover and let go to stop hovering. However, we settled with a space bar to enter hover and the “F” key to toggle hover off. I have my animater already set up and seems to be working fine as is. I have 5 animations in total:
“Idle” = Character is in an idle state
“Walk” = Character walks
“Flight” = Character enters the flight
“Flight State” = Character is in an idle state but is hovering
“Landing” = Character exits flight to return to idle
The Errors I am getting are:
ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
Assets\FlightChracterAnim.cs(54,6): error CS1513: } expecte
Here is the code I have:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FlightCharacterAnim : MonoBehaviour
{
public Animator animator;
public float speed = 100f;
public int grounded = 1;
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
grounded = 0;
animator.SetBool(“Walk”, false);
}
if (Input.GetKeyDown(KeyCode.F))
{
grounded = 1;
animator.SetBool(“Flight”, false);
}
if ((Input.GetAxis(“Horizontal”) != 0) & (grounded = 1))
{
animator.SetBool(“Walk”, true);
transform.Translate(Vector3.right * Time.deltaTime * speed);
if (Input.GetAxis(“Horizontal”) < 0)
{
transform.rotation = Quaternion.Euler(0, 180, 0);
}
if (Input.GetAxis(“Horizontal”) > 0)
{
transform.rotation = Quaternion.Euler(0, 0, 0);
}
}
else
{
animator.SetBool(“Walk”, false);
}
if ((Input.GetAxis(“Horizontal”) != 0) & (grounded = 0))
{
animator.SetBool(“Flight”, true);
transform.Translate(Vector3.right * Time.deltaTime * speed);
if (Input.GetAxis(“Horizontal”) < 0)
{
transform.rotation = Quaternion.Euler(0, 180, 0);
}
if (Input.GetAxis(“Horizontal”) > 0)
{
transform.rotation = Quaternion.Euler(0, 0, 0);
}
}
}
}