Hi guys im creating a click to move script that walk with left mouse button and attack with right one. the move is working fine but when i press attack key (right mouse button) nothing happen. Wt am i missing here?
Another thing im getting this warning too:
Assets/Scripts/Rpg/ClickToMove.cs(9,19): warning CS0108: ClickToMove.animation' hides inherited member UnityEngine.Component.animation’. Use the new keyword if hiding was intended
This is the script
Appreciate any help
using UnityEngine;
using System.Collections;
public class ClickToMove : MonoBehaviour
{
NavMeshAgent navAgent;
Animation animation;
public AnimationClip runAnimation;
public AnimationClip idleAnimation;
public static bool isAttacking;
bool isAttacking = false;
void Awake()
{
animation = GetComponent<Animation> ();
isAttacking = false;
}
public AnimationClip attackAnimation;
// Use this for initialization
void Start ()
{
navAgent = GetComponent<NavMeshAgent>();
}
// Update is called once per frame
void Update ()
{
Move ();
Animate ();
}
void Move()
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Input.GetMouseButtonDown (0))
{
if(Physics.Raycast(ray, out hit, 100))
{
navAgent.SetDestination(hit.point);
}
}
}
void Animate()
{
if (navAgent.velocity.magnitude > 0.5f) {
animation.CrossFade (runAnimation.name);
}
else
{
animation.CrossFade (idleAnimation.name);
}
}
void Attack()
{
if (Input.GetMouseButtonUp(1))
{
isAttacking = true;
animation.CrossFade (attackAnimation.name);
}
}
}
Isn’t the problem because you are running Animate() each frame, which starts an animation even if isAttacking is true? That way you will never see your attack animation, since it is overridden all the time.
im guessing you mean it only ever plays walking animation… you’re going to have to look into bones/layers/weights if you want to play attack/walk/run at the same time, or ensure its playing one or the other.
For now i just want it to walk and if is attacking is not walking… But even i call Animate inside Move method the attack dont work… Latter i will try implement a ability system but i hv time for that just want things simple or now