I have made a fighting game and I don’t know where I should integrate my animation in the script. I have 4 actions : Idle , Walk , Kick One , Kick 2 . My script is for phone controllers , where should I put the animations?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Move : MonoBehaviour
{
private Animator anim;
public float moveSpeed = 300;
public GameObject character;
private Rigidbody characterBody;
private float ScreenWidth;
private Rigidbody rb2d;
public bool isDead = false;
public Vector2 jumpHeight;
public int jumpCount = 0;
internal static object instance;
// Use this for initialization
void Start()
{
ScreenWidth = Screen.width;
characterBody = character.GetComponent<Rigidbody>();
rb2d = this.GetComponent<Rigidbody>();
rb2d.freezeRotation = true;
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
if (isDead) { return; }
if (jumpCount < 3 && (Input.GetMouseButtonDown(0) || Input.GetKeyDown(KeyCode.Space))) //makes player jump
{
GetComponent<Rigidbody>().AddForce(jumpHeight, ForceMode.Impulse);
jumpCount++;
}
jumpCount = 0;
int i = 0;
while (i < Input.touchCount)
{
if (Input.GetTouch(i).position.x > ScreenWidth / 2)
{
RunCharacter(1.0f);
}
if (Input.GetTouch(i).position.x < ScreenWidth / 2)
{
RunCharacter(-1.0f);
}
++i;
}
}
void FixedUpdate()
{
#if UNITY_EDITOR
RunCharacter(Input.GetAxis("Horizontal"));
#endif
}
private void RunCharacter(float horizontalInput)
{
characterBody.AddForce(new Vector2(horizontalInput * moveSpeed * Time.deltaTime, 0));
}
}