Question by
filifjonkaren · Oct 02, 2016 at 05:37 AM ·
c#spawningzombies
Spawn in zombies that are facing me!
I got the AI to work with 1 zombie allredy in when started but i cant spawn in more because it dont find the position that it shuld be facing.
here i have trid to use the position from a script on the player and then use that in the zombie script but i cant get it to work...
error NullReferenceException: Object reference not set to an instance of an object AI.Update () (at Assets/AI.cs:31)
using UnityEngine;
using System.Collections;
public class AI : MonoBehaviour
{
public float _enemyMovementSpeed;
private Transform _fpsTarget;
Rigidbody _rb;
PlayerController _playerController;
Transform _tf;
void Start()
{
_tf = GetComponent<Transform>();
_playerController = GetComponent<PlayerController>();
_rb = GetComponent<Rigidbody>();
}
void Update()
{
//_fpsTarget = _playerController._position;
// if (_fpsTarget != null)
//{
// transform.LookAt(_fpsTarget);
// }
Debug.Log(_playerController.transform.position);
}
}
Comment