using UnityEngine;
using System.Collections;
public class Build : MonoBehaviour {
public GameObject cube1;
public GameObject cube2;
public GameObject cube3;
public GameObject cube4;
public bool Cube1;
public bool Cube2;
public bool Cube3;
public bool Cube4;
public bool block;
private GameObject newCube;
public bool Active;
public bool warning;
public bool clear;
public Inventory check;
public string warningText;
void Start ()
{
}
void Update ()
{
if(Input.GetKeyDown(KeyCode.B) && !Active && !block)
{
if(check.woodCount > 0)
{
if(Cube1)
{
newCube = Instantiate(cube1, new Vector3(transform.position.x,10,transform.position.z) + transform.forward * 4.0f, transform.rotation) as GameObject;
Active = true;
newCube.transform.parent = Camera.main.transform;
//check.woodCount -= 10;
//cube.rigidbody.isKinematic = true;
block = true;
}
if(Cube2)
{
newCube = Instantiate(cube2, new Vector3(transform.position.x,10,transform.position.z) + transform.forward * 4.0f, transform.rotation) as GameObject;
Active = true;
newCube.transform.parent = Camera.main.transform;
//check.woodCount -= 10;
//cube.rigidbody.isKinematic = true;
block = true;
}
if(Cube3)
{
newCube = Instantiate(cube3, new Vector3(transform.position.x,10,transform.position.z) + transform.forward * 4.0f, transform.rotation) as GameObject;
Active = true;
newCube.transform.parent = Camera.main.transform;
//check.woodCount -= 10;
//cube.rigidbody.isKinematic = true;
block = true;
}
if(Cube4)
{
newCube = Instantiate(cube4, new Vector3(transform.position.x,10,transform.position.z) + transform.forward * 4.0f, transform.rotation) as GameObject;
Active = true;
newCube.transform.parent = Camera.main.transform;
//check.woodCount -= 10;
//cube.rigidbody.isKinematic = true;
block = true;
}
}
else
{
warningText = "You don't have wood !";
warning = true;
}
}
if(Input.GetKeyDown(KeyCode.V) && Active && block)
{
newCube.transform.parent = null;
//cube.rigidbody.isKinematic = false;
Active = false;
clear = true;
block = false;
}
if(clear)
{
Cube1 = false;
Cube2 = false;
Cube3 = false;
Cube4 = false;
clear = false;
}
}
}
My problem:
I can spawn cube, it spawn in fron of me, 10 forward like in script, but after that when i move my character, cube doesn’t follow ;/ it just rotate with me, nothnig else. I have First Person Character from Sample Asstes .