- Home /
Question by
Seventh Stealth · Sep 07, 2013 at 06:29 PM ·
javascriptvectorfunction update
Could someone fix this : It says expressions must only be executed ofr their side-effects
private var Bullet : GameObject;
function Update(){
//Get input position in pixels (screen-coordinates);
var screenPos : Vector2;(Input.touches[0].position);
//Convert from screen coordinates (pixels) to world-coordinates;
var worldPos : Vector3;(camera.ScreenToWorldPoint(new Vector3(screenPos.x, screenPos.y, camera.nearClipPlane)));
//Move the empty-object to the location of click/tap;
transform.position = worldPos;
//Instantiate a new object at that location
Instantiate(Bullet , worldPos , Quaternion.identity);
//Fire away!
Bullet.rigidbody.AddForce(transform.forward * 5000);
}
Error reads : Expressions must only be executed for their side effects (4/47)
Comment
Best Answer
Answer by aldonaletto · Sep 07, 2013 at 06:47 PM
Usually this error means something like "what the hell means that!?!?" - coincidentally, the same thing we think when this message appears. In this case, the expressions should be assigned to the Vector2 and Vector3 variables, but there's a semicolon instead of an equal sign (the parenthesis aren't needed too):
...
//Get input position in pixels (screen-coordinates);
var screenPos : Vector2 = Input.touches[0].position;
//Convert from screen coordinates (pixels) to world-coordinates;
var worldPos : Vector3 = camera.ScreenToWorldPoint(new Vector3(screenPos.x, screenPos.y, camera.nearClipPlane));
...
NOTE: This script must be attached to the camera, or Null Reference errors will damn you!
Your answer
![](https://koobas.hobune.stream/wayback/20220613113742im_/https://answers.unity.com/themes/thub/images/avi.jpg)