- Home /
creating a GameObject Instead of a Cube
hello :), i have been trying to figure this out for ages now, all i want is instead of a cube been created i want a gameobject of my choice basically i have modeled something, nad instead of the cube i want this game object but i dunno how to do it here is the code, please help :(
var range : float = Mathf.Infinity;
var hit : RaycastHit;
function Update() {
if(Input.GetMouseButtonDown(1)){
Build();
}
}
function Build() {
if(HitBlock()){
var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
cube.transform.position = hit.transform.position + hit.normal;
}
}
function HitBlock() : boolean
{
return Physics.Raycast(transform.position, transform.forward, hit, range);
}
Thanks.
Answer by Piflik · May 05, 2012 at 10:37 PM
Make a Prefab from your object. Then you can instantiate the object with your code.
Your answer
Follow this Question
Related Questions
Component or Independent class 1 Answer
Cannot implicitly convert type `UnityEngine.GameObject[]' to `UnityEngine.GameObject' 1 Answer
Smooth aim 2 Answers
Set Rigidbody variable to Prefab using code 1 Answer
Sniper Zoom!!! 1 Answer