Hi,
In my game I want it so when the player enters the enemy raycast it goes towards him and attacks.
However I'm getting Error CS1503, the console says Assets/scripts/EnemyScript.cs(20,23): error CS1503: Argument `#2' cannot convert `object' expression to type `UnityEngine.Vector3' and error CS1502 he best overloaded method match for `UnityEngine.Debug.DrawLine(UnityEngine.Vector3, UnityEngine.Vector3, UnityEngine.Color)' has some invalid arguments
I also get error CS0019 it says Operator `-' cannot be applied to operands of type `UnityEngine.Vector3' and `float'
using UnityEngine;
using System.Collections;
public class EnemyScript : MonoBehaviour {
bool seenPlayer = false;
RaycastHit2D seePlayer;
Animator anim;
void Start()
{
anim = GetComponent ();
}
void Update()
{
//Just a debug visual representation of the Linecast, can only see this in scene view! Doesn't actually do anything!
Debug.DrawLine(transform.position, (transform.position - 10f), Color.magenta);
//Using linecast which takes (start point, end point, layermask) so we can make it only detect objects with specified layers
//its wrapped in an if statement, so that while the tip of the Linecast is touching an object with layer, the code inside executes
if(Physics2D.Linecast(transform.position, (transform.position - 10f), 1 << LayerMask.NameToLayer("GameObject")))
{
//store the collider object the Linecast hit so that we can do something with that specific object
//each time the linecast touches a new object with layer
seePlayer = Physics2D.Linecast(transform.position, (transform.position - 10f), 1 << LayerMask.NameToLayer("Guard"));
seenPlayer = true; //since the linecase is touching the guard and we are in range, we can now interact!
}
else
{
seenPlayer = false; //if the linecast is not touching
}
}
}
^ my script
↧