- Home /
Why is my var not changing?
I have code to shoot a projectile downwards. As I started on it I ran into an early bug that I can't figure out. I have a speed var to change how fast the object flies thru the air. But no matter what I put it keeps coming out as the number 1. What is going on ?
#pragma strict
var projectile : GameObject;
var FireSpeedMin : float;// Min ammount of seconds between fire
var FireSpeedMax : float;// Max ammount of seconds between fire
var speed : int; // Always make this negitive
//Private
private var firedObject : GameObject;
function Start ()
{
firedObject = Instantiate(projectile, gameObject.transform.position, Quaternion.identity);
print(speed);
firedObject.rigidbody2D.AddForce(Vector2(0, speed));
}
function Update ()
{
}
Answer by screenname_taken · Jun 19, 2014 at 05:26 PM
It's declared as an integer. So everything will be round down.
Should be float instead. If you put 0.1 into an int, it will go in as 0.
The numbers I have put in have ranged from -100 to 100. I originally had it as a float and thought that maybe somehow it was throwing it into the problem so I tried it as an int.
Your answer
Follow this Question
Related Questions
2D 360 degress platformer example needed 0 Answers
How can I make a game object move in parabolic motion as if it were under gravity? 2 Answers
Is it okay to use ForceMode.VelocityChange in Update()? 1 Answer
Child object's collider (on a different layer) is interfering with parent Physics... 0 Answers
Disable/Enable Colliders 1 Answer