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)
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!