- Home /
Problem with updating an integer.
I have a gameObject that I am trying to get the rotation.x of. This is then to be saved to an integer called velocity. The problem is, I am getting the 'Expressions in statement must only be executed for their side-effects" error. I know this means that my code isnt doing anything and this may be due to C# handling the integer in a certain way that is different to unityscript.
The code is as follows:
var changeType : changeMaterialType; var catapult : GameObject; var velocity : int;
function Start(){ velocity = 0; }
function Update () {
velocity == catapult.transform.rotation.x;
if(rigidbody.isKinematic == false) { if(constantForce.force.y >= -50) { gameObject.constantForce.force.y -= changeType.currentProjectile.rigidbody.mass * 10/velocity; }
if(constantForce.force.z <= 10 && constantForce.force.z >= 0)
{
gameObject.constantForce.force.z += 1;
}
if(constantForce.force.z == 10)
{
gameObject.constantForce.force.z -= 2;
}
} }
I have the velocity int starting at 0 and want it to be equal to the rotation of my catapult gameobject when updating.
Answer by BiG · Apr 25, 2012 at 10:11 AM
This line is strange:
velocity == catapult.transform.rotation.x;
since it's a double "=" outside an if statement. It should be
velocity = catapult.transform.rotation.x;
But I'm not sure this will solve all your problems.
thanks i must have overlooked this. the problem now is that the velocity int is just staying as 0 all the time
Stupid question: is rigidbody.is$$anonymous$$inematic setted to false? It's the only way to work :) By the way, I wish to tell you another thing: the second inner if (if(constantForce.force.z == 10)) will never be executed: look at the first inner one, and you'll see that the case z=10 is already considered.
the rigidbody is user controlled for a time at the start of the game and is therefore kinematic. it is then changed to false when firing it as it should then be affected by the constant force.
do you know why my velocity int is always set at 0? even at runtime, it does not update to the rotation of the catapult which can be seen to change when paused.
Your answer