I’ve been working on this for 2 hours now can’t seem to figure out where I’m going wrong
I have 2 scripts
In one script called Move_Soldier I have a code moving the soldier and a boolean called movement = false
#pragma strict
var speed : float = 5.0;
var movement : boolean = true;
function Start () {
}
function Update () {
GameObject.Find("soldier2").transform.Translate(Vector3(0,0,speed) * Time.deltaTime);
}
In the other script or my bullet script with all the ray cast I want to say if bullet hits trigger of soldier call movement variable from Move_Soldier script and then say movement = false and animation of soldier moving (via code) stops so instead of the soldier falling on the ground and still moving, I want him to just stay in one position.
So after I access my variable from Move_Soldier script I get this error
Assets/Models/bulletscript.js(36,20): BCE0005: Unknown identifier: ‘MoveScript’.
How can it be unknown if I already called it unless I am doing it wrong. I already had another variable from another script working so I sued the same logic but this ain’t working.
var BulletSpeed = 50;
var speed : float = 5.0;
function Start () {
}
function Update () {
var MoveScript : Move_Soldier = GetComponent(Move_Soldier);
transform.Translate(Vector3.forward * Time.deltaTime * BulletSpeed);
var hit : RaycastHit;
if (Physics.Raycast(transform.position, transform.forward, hit))
{
if (hit.collider.gameObject.tag == "k")
GameObject.Find("soldier").animation.Play("soldierDieBack");
if (hit.collider.gameObject.tag == "z")
GameObject.Find("soldier2").animation.Play("soldierDieBack");
movement = false;
}
}
function activation () {
if (MoveScript.movement == false)
{
Debug.Log("enemy movement has to stop, put in the stoping code now");
}
}
Now the interesting thing is, if I get rid of my activation function above and copy paste the code below in the update function then it works but it gives me a null object reference error after I shoot.
if (MoveScript.movement == false)
{
Debug.Log("enemy movement has to stop, put in the stoping code now");
}
NullReferenceException: Object reference not set to an instance of an object
bulletscript.Update () (at Assets/Models/bulletscript.js:31)