Hi everyone. I’m fairly new to Unity3D - actually programming in general.
I’m trying to do a basic game with PowerUps and a few animations.
But there is a already the first problem, I can’t get the PowerUps to do what i want them to.
What i planis that when the player collides with the PowerUp (BoxCollider) the players Animator Speed should increase for a limited time (10sec or so).
I wrote a script to change the Animator Speed in a variable (float) and it works.
But I am having trouble changing that variable, through the script attached to the PowerUp when the collision happens.
Already tried a lot of things, but nothing seems to work for me. I hope someone can help me out.
The script that manipulates the Animator Speed called “AnimatorVar” attached to “Player”
public var animator:Animator;
public var speed:float;
function Start(){
animator=GetComponent(Animator);
}
function Update () {
animator.speed = 1;
}
This is the Script i did for the PowerUp attached to “Trigger” (basicly only a test for the collider itself with no functionality other than destroyng the box after the collison)
function OnTriggerEnter () {
GameObject.Destroy (gameObject) ;
}
So what i need is basically a way to change the variable from = 1 to for example = 2 and give it a timer of 10 secs.
To change a variable on another script you have a few choices. One less choice, and my preferred method, which is exclusive to C#, so you using Java can not. One reason I suggest switching languages.
In C# you can have a script as a variable. Now, with that variable, you have access to that script from this script.
First of all thank you for your reply. Using C# is not really an option for me, as i have no knowledge in using it and i don’t want to mix languages here.
I did try the GetComponent Method but just can’t get it to work.
public static var animator:Animator;
public static var speed:float;
function Start(){
animator=GetComponent(Animator);
}
function Update () {
animator.speed = 1;
}
Thanks to everybody that contributed to this. I have managed to get what i wanted by making the player the one triggering the collision and attaching a script to him.