After a long search I found some code to get a prefab on the same location I touch and it works.
My Question is, is there a way to get the prefab instantiate a few units above the point i touch?
The prefab is a cube with a rigid body so they fall at the point I touch.
Thank in advance!
public var newObject : GameObject;
var layerMask = 1 << 8;
function Update () {
for (var Touch : Touch in Input.touches) {
if (Touch.phase == TouchPhase.Began) {
var ray = Camera.main.ScreenPointToRay (Touch.position);
var hit: RaycastHit;
if (Physics.Raycast (ray, hit, layerMask)) {
Instantiate (newObject, hit.point, transform.rotation);
}
}
}
}
I tried to put you code in my instantiate line but getting errors, i’m sure it’s me that is doing it wrong
I have very very limited programming know how.
Can you please show me how to put you code in my script?
Still not working in my case when I click the object some times instantiated in the right place and some times is not, not really stable!!! any one who has tried it?