I’m trying to make it so that my enemy AI can shoot at and target the player in a 2D game. I get the errors:
Assets/Meep/Dialogues/enemyshoot.cs(21,35): error CS0118: enemyshoot.Projectile' is a
field’ but a ‘type’ was expected
Assets/Meep/Dialogues/enemyshoot.cs(22,28): error CS1061: Type object' does not contain a definition for
instantiate’ and no extension method instantiate' of type
object’ could be found (are you missing a using directive or an assembly reference?)
This is my current script:
using UnityEngine;
using System.Collections;
public class enemyshoot : MonoBehaviour {
public GameObject _controller;
private Vector2 _direction;
private Vector2 _startPosition;
private float _canFireIn;
public GameObject Projectile;
public void Start (){
//_controller = GetComponent<>();
_direction = new Vector2(-1, 0);
_startPosition = transform.position;
}
public void Update() {
if ((_canFireIn -= Time.deltaTime) > 0)
return;
var raycast = Physics2D.Raycast(transform.position, _direction, 10, 1 << LayerMask.NameToLayer("Player"));
if (!raycast)
return;
var projectile = (Projectile) Instantiate(Projectile, transform.position, transform.rotation);
projectile.instantiate(gameObject, _direction, _controller.Velocity);
//_canFireIn = FireRate;
}
}