Argument `#1' cannot convert `float' expression to type `UnityEngine.Vector3 ?
i'm trying to make an Advanced AI script but i'm getting the following errors: Assets/Scripts/AI/AvancedAI.cs(38,24): error CS1503: Argument #1' cannot convert float' expression to type UnityEngine.Vector3' Assets/Scripts/AI/AvancedAI.cs(38,24): error CS1503: Argument #1' cannot convert float' expression to type UnityEngine.Vector3' using UnityEngine;
public class AvancedAI : MonoBehaviour {
public int health = 100;
public float viewRange = 25f;
public float attackRange = 5f;
public bool isChasing = false;
private UnityEngine.AI.NavMeshAgent agent;
private Transform playerTransform;
private void Start()
{
agent = GetComponent<UnityEngine.AI.NavMeshAgent> ();
}
private void Update()
{
Ray ray = new Ray (transform.position, Vector3.forward);
RaycastHit hitInfo;
if (Physics.Raycast (ray, out hitInfo, viewRange))
{
if (hitInfo.collider.tag == "Player")
{
if (isChasing == false)
{
playerTransform = hitInfo.collider.GetComponent<Transform> ();
isChasing = true;
}
}
}
if (Physics.Raycast (viewRange, out hitInfo, attackRange))
Debug.DrawRay (ray.origin, ray.direction * viewRange, Color.red);
if (isChasing == true)
{
agent.SetDestination (playerTransform.position);
}
}
}
What did i do wrong?
Answer by AurimasBlazulionis · Feb 20, 2017 at 08:18 AM
I think the problem is with the second raycast first argument viewRange. You should change it to ray.
Do not forget to accept the answers that are correct.
Your answer
Follow this Question
Related Questions
How do you make a GameObject move on Update endlessly? 1 Answer
Player Floating 0 Answers
How can I make this translation smoother? 0 Answers
Help me with my ai controller 1 Answer
[Urgent] Finding Nearest Target 2 Answers