- Home /
Question by
sirbacca · Jul 18, 2017 at 05:50 AM ·
animationcharactercontrolleranimator controllercharacter movementscriptingproblem
Why are my animations not working correctly? Thanks!
Currently, i want my character to by default start at idle, then walk when you click somewhere that isn't intractable. I setup my animation controller and have a condition called ismoving. But for some reason, it either only plays the idle or only plays the walk. if someone could help that'd be great. Thanks so much!
using System.Collections; using UnityEngine; using UnityEngine.AI;
public class WorldInteraction : MonoBehaviour {
NavMeshAgent playerAgent;
public bool isMoving;
void Start()
{
playerAgent = GetComponent<NavMeshAgent>();
}
void Update()
{
if (Input.GetMouseButtonDown(0) && !UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject())
GetInteraction();
}
void GetInteraction()
{
Ray interactionRay = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit interactionInfo;
if (Physics.Raycast(interactionRay, out interactionInfo, Mathf.Infinity))
{
GameObject interactedObject = interactionInfo.collider.gameObject;
if (interactedObject.tag == "Interactable Object")
{
Debug.Log("Interactable Interacted.");
}
else
{
playerAgent.destination = interactionInfo.point;
isMoving = true;
}
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Character will not go from Ide to Walk 1 Answer
How to make char animation idle 0 Answers