Hello all,
This was honesty my last resort I looked for answers on Google and Stack Overflow, but I haven’t found a solution to help me figure out what this compile error means and how to fix it. The Unity API.Vector3 says there must be 3 parameters, but it doesn’t say anything about error CS0426. Could someone let me know where I messed up if it’s not asking too much .
This code is for a little experiment I’m messing around with to make a skeleton move to random locations as pictured below. Once I slide the “player” cylinder into the skeleton’s collider he attacks like he should based off the code and anim controller, but he swings and still continues to move toward the random destination game object. So I’m trying to use a Vector3.MoveTowards to make the skeleton stop while the “player” is inside the collider, but I can’t clear this error to see if this Vector3.MoveTowards will even work.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class RoamingSkeleton : MonoBehaviour
{
public GameObject destinationLocation;
public NavMeshAgent theAgent;
public int Xpos;
public int zPos;
public Animator anim;
public GameObject thePlayer;
// Start is called before the first frame update
void Start()
{
theAgent = GetComponent<NavMeshAgent>();
anim = GetComponent<Animator>();
theAgent.SetDestination(destinationLocation.transform.position);
}
public void OnTriggerEnter(Collider other)
{
if (other.tag == "Player")
{
// Stop moving to destinationLocation and start attack animation at the players position.
anim.SetBool("isWalking", false);
theAgent.transform.position = new Vector3.MoveTowards(thePlayer.transform.position, transform.rotation);
anim.SetBool("isAttacking", true);
}
}
public void OnTriggerExit(Collider other)
{
if (other.tag == "Player")
{
// Start walking animation and go to destinationLocation.
anim.SetBool("isWalking", true);
theAgent.SetDestination(destinationLocation.transform.position);
}
}
}