- Home /
C# if statement not working!!
Ok, guys this might be stupid but I just cannot figure out what on earth is wrong with this simple code:
public class NewBehaviourScript1 : MonoBehaviour {
float speed = 10;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
transform.Translate(Vector3.left * Time.deltaTime * speed);
Vector3 pos = Camera.main.WorldToViewportPoint(transform.position);
if (pos.x > 0) {
speed * 3;
}
}
}
I get this error:
Unexpected symbol
3', expecting
[',<operator>', or
identifier'
If however I change the multiplication to an additon or anything else(even if a Debug.Log) the error goes away. Whats wrong?????
Answer by heino-heinrich · Feb 05, 2016 at 11:03 PM
You have to write speed = speed * 3; then it should work.
You know, there's an "edit" button on the right if you click on the "gear button" on your post.
I added the "*" ^^.
btw: for the statement:
x = x * y;
there's a shortcut operator (`*=`):
x *= y;
// on topic:
speed *= 3;
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
[c#} Combining if statements 1 Answer
Illuminating a 3D object's edges OnMouseOver (script in c#)? 1 Answer
Conflicting Animator SetTrigger 0 Answers