- Home /
getting a sum from two scripts
Alright, I had no idea on how to word this into a short "topic" question, not even really sure on the terminology... but here's my dilemma: I have three .js scripts, one for car, one for racer, and one for player.
In the car script ("KartScript.js") I have the following:
public var krtSpdLand : float;
which is a float designated in the unity engine's inspector.
In the racer script ("RacerScript.js") I have the following:
racSpdLand = 3;
My problem is that I cannot seem to get the player script ("PlayerScript.js") to do the math that I want it to... which is:
spdLand = RacerScript.racSpdLand + KartScript.krtSpdLand;
I am trying to get the sum of the 2 floats to become the float value for the Player Script's "spdLand."
I have searched and I cannot seem to find anything that even resembles this.
Thanks ahead of time for your help.
So the way you are trying to write it would require the variables to be static, but that may not be what you need.
Try this: http://unitygems.com/script-interaction-tutorial-getcomponent-unityscript/
Answer by fafase · Mar 06, 2014 at 05:58 AM
You need to look into GetComponent : http://unitygems.com/script-interaction1/
Your answer
Follow this Question
Related Questions
A fast triangle triangle intersection algorithm for unity? 4 Answers
How do I check for triangle triangle intersection? 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Changing gameobjects Float from another script? 1 Answer
How do I find the inverse cosine ??? 1 Answer