Quantcast
Channel: Answers by "ransomink"
Viewing all articles
Browse latest Browse all 80

Answer by ransomink

$
0
0
First off, no one can help if you can't properly tell us the names of your scripts. Adequate info is necessary. Secondly, [@ThomasMarsh][1] gave you the correct answer for accessing a variable from another script. Inside of the script called "CharWeapon" (the actual script you are calling from) > "The other script which I call from is called something like charweapon or something like that." create a private variable with the same name as the script you want to access, but in lowercase. private var move : Move; // Reference to the Move script Then setup the instance to the script in the Awake () function. function Awake () { move = GetComponent ( Move ); // Set a reference to the Move script } In your code you have... move = GetComponent ( Player ); ... which is incorrect because "Player" is the gameobject, not the script you're trying to access. There are also other factors at play: the "CharWeapon" and "Move" script **must** be attached to the "Player" gameobject, and "runSpeed" **has** to be a public variable in order to access it. You do not have to cast a type to "runSpeed", you already - should have anyway - done so inside the "Move" script. Also, using 50.0f is C# syntax; with UnityScript it is not needed. The code should be as follows... move.runSpeed = 50.0; [1]: http://answers.unity3d.com/users/56317/thomasmarsh.html

Viewing all articles
Browse latest Browse all 80

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>