Copied and merged from comment:
var Firefrom : Transform;
var currentbrick: GameObject;
var finalbrick : GameObject;
function Update ()
var hit : RaycastHit;
var roundpos : Vector3;
if(Physics.Raycast(Firefrom.position, Firefrom.forward, hit))
roundpos = hit.point - Firefrom.forward.normalized * 0.05;
roundpos *= 2.0;
roundpos = Vector3(Mathf.Round(roundpos.x), Mathf.Round(roundpos.y), Mathf.Round(roundpos.z));
roundpos /= 2.0;
var Temp = Instantiate(currentbrick, roundpos , Quaternion.LookRotation(Vector3.zero));
Temp.tranform.position = Vector3(1,2,3);
The last part will not work, there is literaly no way to move the thing. (this isn’t full script)
Well your code can’t work. Update is called once every frame. However this if statement is only true for one frame, the moment you press your fire button:
So everything within the body of the is block is executed “once” the moment you press fire.
Inside the body you have another “button down” check for the “w” key, however it’s nearly impossible that you press both keys at the exact same time. If you press w 10ms later the next frame the first if statement is false again.
It seems you’re lacking of some basic control flow rules. From your script it’s hard to tell what you actually want to do… You clamp the position to a multiple of 2, which is fine, but why do you want to set the position of the instantiated “brick” to a fix world position when you press a button?
Keep in mind that you can press fire multiple times which would instantiate multiple bricks. If you want to somehow “move” the brick with a key press, which brick do you want to move? the last created?
First you should be clear what you want to do and once that’s clear you start coding it. If you can’t explaint what you want to do, you can’t code it!