I’m following this tutorial:
http://blog.lessmilk.com/unity-spaceshooter-2/
And I’ve modified the enemy script
public var speed : float = -5;
function Start () {
GetComponent.<Rigidbody2D>().velocity.y = -5;
Debug.Log(speed);
}
function OnBecameInvisible() {
Destroy(gameObject);
}
speed is always positive, even if I set it to a negative value. If I set velocity to speed, The rocks move up instead of down.
What can I do to make speed negative?
Since your speed variable is public, changing the value in the script won’t change tha actual value. All public variables are serialized in the inspector. You should set / change the value in the inspector when you select the gameobject to which this script is attached to.
Since you changed the type from float to int the inspector sees it as a new variable and initially uses the value in your script. The value should be a float value, just make sure you set the right value in the inspector.