Question by
scottsniper77 · Apr 12, 2016 at 03:52 PM ·
respawnresources.loadrespawner
Why is my player not being found after being respawned
Here is my script:
var Distance;
var Target : GameObject;
var lookAtDistance = 25.0;
var chaseRange = 15.0;
var attackRange = 1.5;
var moveSpeed = 5.0;
var Damping = 6.0;
var attackRepeatTime = 1;
var MaxHealth = 100;
var Health : int;
var TheDammage = 40;
private var attackTime : float;
var controller : CharacterController;
var gravity : float = 20.0;
var rigidbdy : Component;
private var MoveDirection : Vector3 = Vector3.zero;
function Awake () {
Target = Resources.Load("Player/FPScontroller 1", GameObject) as GameObject;
}
function Start ()
{
attackTime = Time.time;
Health = MaxHealth;
GetComponent.<Rigidbody>().isKinematic = true;
GetComponent.<Rigidbody>().detectCollisions = false;
}
function Update ()
{
if(RespawnMenuV2.playerIsDead == false)
{
Distance = Vector3.Distance(Target.transform.position, transform.position);
if (Distance < lookAtDistance)
{
lookAt();
}
if (Distance > lookAtDistance)
{
GetComponent.<Renderer>().material.color = Color.green;
}
if (Distance < attackRange)
{
attack();
}
else if (Distance < chaseRange)
{
chase ();
}
}
}
function ApplyDammage (TheDammage : int)
{
Health -= TheDammage;
if(Health <= 0)
{
Dead();
}
}
function Dead()
{
GetComponent.<Rigidbody>().isKinematic = false;
GetComponent.<Rigidbody>().detectCollisions = true;
PlayerStatsV2.zombieskilled ++;
PlayerHumanity.humanity ++;
Destroy(this);
}
function lookAt ()
{
GetComponent.<Renderer>().material.color = Color.yellow;
var rotation = Quaternion.LookRotation(Target.transform.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * Damping);
}
function chase ()
{
GetComponent.<Renderer>().material.color = Color.red;
moveDirection = transform.forward;
moveDirection *= moveSpeed;
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
function attack ()
{
if (Time.time > attackTime)
{
Target.SendMessage("ApplyDammage", TheDammage);
Debug.Log("The Enemy Has Attacked");
attackTime = Time.time + attackRepeatTime;
}
}
function ApplyDammage ()
{
chaseRange += 30;
moveSpeed += 2;
lookAtDistance += 40;
}
I get this error loads of times:
NullReferenceException: Object reference not set to an instance of an object
AdvancedAIV2.Update () (at Assets/Zombies/AI/AdvancedAIV2.js:38)
Comment
Your answer
Follow this Question
Related Questions
Respawn doesn't work ? 0 Answers
Unity/C# Respawn and score Problem 1 Answer
Death from collision 1 Answer