Boss AI Help in a 2D Platform game
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class walkBehavior : StateMachineBehaviour {
public float timer;
public float minTime;
public float maxTime;
private Transform playerPos;
public float speed;
override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
playerPos = GameObject.FindGameObjectWithTag("Player").GetComponent<Transform>();
timer = Random.Range(minTime, maxTime);
}
override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
if (timer <= 0)
{
animator.SetTrigger("idle");
}
else
{
timer -= Time.deltaTime;
}
Vector2 target = new Vector2(playerPos.position.x, animator.transform.position.y);
//need to fix
animator.transform.position = Vector2.MoveTowards(animator.transform.position, target, speed * Time.deltaTime);
}
override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
}
So everything works well BUT when he switches to his walk animation,he immediately disappears. My boss shows up in the scene view but not the game view
Comment