Hi,
So in my game when the player enters the linecast of the enemy i want the enemy to move towards him.
But I get this Assets/scripts/EnemyScript.cs(23,22): error CS0103: The name `GetComponenet’ does not exist in the current context
It highlights:
rb = GetComponenet<Rigidbody2D> ();
Full script:
using UnityEngine;
using System.Collections;
public class EnemyScript : MonoBehaviour {
bool seenPlayer;
RaycastHit2D seePlayer;
public Rigidbody2D rb;
public Vector2 newPos;
float maxSpeed = 10f;
Animator anim;
GameObject player;
void Start()
{
anim = GetComponent<Animator> ();
**rb = GetComponenet<Rigidbody2D> ();**
player = GameObject.FindWithTag("Player");
}
void FixedUpdate()
{
//Just a debug visual representation of the Linecast, can only see this in scene view! Doesn't actually do anything!
Debug.DrawLine(transform.position, newPos , 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 (interactCheck.position) is touching an object with layer 'Guard', the code inside executes
if(Physics2D.Linecast(transform.position,newPos, 8 << LayerMask.NameToLayer("Player")))
{
//we store the collider object the Linecast hit so that we can do something with that specific object, ie. the guard
//each time the linecast touches a new object with layer "guard", it updates 'interacted' with that specific object instance
Physics2D.Linecast(transform.position,newPos, 8 << LayerMask.NameToLayer("Player"));
seenPlayer = true; //since the linecase is touching the guard and we are in range, we can now interact!
if(seenPlayer == true)
{
Debug.Log("worked");
rigidbody2D.velocity = new Vector2(1, rigidbody2D.velocity.y);
}
}
else
{
seenPlayer = false; //if the linecast is not touching a guard, we cannot interact
}
}
}