- Home /
Question by
3 · Feb 22, 2013 at 04:12 AM ·
variablegetcomponentfind
Why can't I change another script's variable with this script? Thanks,
So the call for audio.play from the same if statement is working, however this line isn't:
GameObject.Find("Computer Scare").GetComponent(Follow).speed - 2;
Even though its identicle to everything I've looked up, I cant seem to change the speed variable from the Follow script on the Computer Scare gameobject. I'm not really sure why, and any help would be greatly appricated, I'm pretty much desperate now. Thanks,
Here is that section of the script: By the way, I've tried the stuff in // already
if (ammoamount > 0 && reloadTime < nextFireTime) {
ammoamount--;
nextFireTime = 0;
pistol.animation.Play("Shoot");
audio.Play();
if (hit.collider.gameObject.name == "Computer Scare"){
target.audio.Play();
//var speed = transform.Find("Computer Scare").GetComponent(Follow).speed;
GameObject.Find("Computer Scare").GetComponent(Follow).speed - 2;
//enemy.GetComponent.Speed = 1.6;
}
}
thanks again
Comment
Best Answer
Answer by AppTechStudios · Feb 22, 2013 at 04:32 AM
Try making something like this:
var varName : Follow;
varName = GameObject.Find("Computer Scare").GetComponent(Follow);
varName.speed - 2;
Hopefully that works.
Thanks a quadrillion! (Fun Fact: Thats more than a million)
though I suggest to anyone reading this to use
varName.speed --;
sets it to -2 automatically,
Saved me hours, thanks.