- Home /
This question was
closed Nov 19, 2014 at 02:37 PM by
meat5000 for the following reason:
Done to Death! Please search for one of the thousands of answers on GetComponent and collisions already in existence.
Question by
foob · Nov 19, 2014 at 02:28 PM ·
c#variablejumpontriggerenter
How to Change a variable in another script when ontriggerenter
Hi, I am looking to change the jumpheight variable set by another script called "BallControl" when i enter a trigger, and im not sure how to do it. Here is what i have so far, but there are many errors and its not working whatsoever.
function OnTriggerEnter (Collider) {
BallControl BallControl = GetComponent<BallControl>();
JumpHeight = 15();
}
And here is what i have in my BallControl script
var rotationSpeed = 100;
var jumpHeight = 8;
private var isFalling = false;
function Update ()
{
//Handle ball rotation.
var rotation : float = Input.GetAxis ("Horizontal") * rotationSpeed;
rotation *= Time.deltaTime;
rigidbody.AddRelativeTorque (Vector3.back * rotation);
if (Input.GetKeyDown(KeyCode.W) && isFalling == false)
{
rigidbody.velocity.y = jumpHeight;
}
isFalling = true;
}
function OnCollisionStay ()
{
isFalling = false;
}
Thank you in advance
Comment
You need to "Find" the object you are trying to pull a script from. Usually in a collision/trigger this is achieved by accessing the collision or collider as an argument of the function.