Hi
Rookie question, but I am trying to get the “speed” variable from a script called “CheckSpeed” in the “Player” game object. I have checked every spelling and it insists on saying:
“‘speed’ is not a member of ‘UnityEngine.Component’”
What am I doing wrong?
My Script So Far:
var bullet : Rigidbody;
var bulletSpeed = 100;
var shipSpeed : float;
function Update () {
shipSpeed = transform.Find("Player").GetComponent("CheckSpeed").speed; // ???
if (Input.GetMouseButtonDown(0))
{
FireGun();
}
}
function FireGun()
{
var clone = Instantiate(bullet, transform.position, transform.rotation);
audio.Play();
clone.velocity = transform.TransformDirection(Vector3(0, 0, bulletSpeed + shipSpeed));
Destroy (clone.gameObject, 3);
}
This should be a very simple solution, but it has stumped me for a good hour. I have never got the hang of referencing variables from other scripts/gameobjects. I wish I could just say stuff like “script.parent.parent.Part”
Also I’d like to add, I know this question has been asked a lot and there is a good page by Unity explaining a solution. But despite reading and following them, it doesn’t seem to help.
Thanks