Hello guys and girls.
I am currently making a survival game, just for the challange and i just started working on the building system, but i just ran into a problem i just can’t seem to find information on this subject by google searching(might be searching the wrong words/terms).
Okay so is the code i have to far:
var RayHit : RaycastHit;
var RayPL : int = 10; //RayPlaceLenght
var InventoryInfo : InventoryText;
var Foundation : GameObject;
function Start ()
{
InventoryInfo = gameObject.Find("Player").GetComponent(InventoryText);
}
function Update ()
{
var RayPlacing1 : Ray = Camera.main.ViewportPointToRay (Vector3(0.5,0.5,0)); //This is the center of the screen, the point where i want to place the object foundation.
if(InventoryInfo.PlacingFDT == true)
{
if((Physics.Raycast(RayPlacing1, RayHit, RayPL))) //Doing the raycast from the middle of the screen.
{
print("RaycastHit " + RayHit.collider.gameObject.name); //Just checking the name of the object i hit.
if(RayHit.collider.gameObject.tag == "Terrain") //if i hit the terrain that have the tag "Terrain", do the following.
{
print("Insert prebuild foundation code here"); //This is the line i need help to do, i want to instantiate a single gameobject that is placed at the RayHit point, so i dont make multiple objects when i look around.
if(Input.GetKeyDown(KeyCode.Mouse0)) //Press the mouse to build acutal object
{
Instantiate(Foundation, RayHit.point ,Quaternion.identity); //This is where i place the actual object.
}
}
}
}
}
So the thing i need help with is, how i place a single gameobject and then have it placed at the point where my RaycastHit hits the terrain. I tried with instantiate and it didn’t work.
Thanks in advance.
Renaxi