Why wont my object Instantiate?
I have a player that places objects onto the floor as he walks. After the fire1 input within the update update function the script should instantiate an object and perform some other computations, but when I use this script the object does not appear to the screen even though all other computations and actions seem to be working correctly. Sorry for the noob code or question but I just cannot figure out why my plank does not appear on screen. Also in case it matters main_script.plank_limit = 20.
public GameObject plank;
public float speed;
public static List<GameObject> planks;
private Vector2 right = Vector2.right;
private Vector2 curr_vel;
private Rigidbody builder_body;
private Vector3 builder_location;
private Vector3 plank_place;
private Vector3 plank_offset;
private main main_script;
public void turnplayer() {
curr_vel = curr_vel * -1;
}
public void add_plank() {
planks.Add((GameObject)(Instantiate(plank,plank_place,Quaternion.identity)));
}
public int plank_on_screen() {
return planks.Count;
}
public void destroy_plank() {
Destroy(planks[0]);
planks.RemoveAt(0);
}
void Awake () {
planks = new List<GameObject> ();
curr_vel = right; //Builder Initially Moves to the Right
builder_body = GetComponent<Rigidbody>();
plank_offset = new Vector3 (2.5f, -1.28f, 0f); // Determined Offset Between Player and Plank
}
void Start() {
main_script = GetComponent<main> ();
}
void FixedUpdate () {
builder_body.velocity = curr_vel * speed;
}
void Update() {
builder_location = transform.position; //Constantly Updates Players Position
plank_place = builder_location + plank_offset; // Updates Position a new plank would be placed
if (Input.GetButtonDown("Fire1") && main_script.planks_in_hand > 0) {
turnplayer();
add_plank();
main_script.dec_plank_in_hand();
if (plank_on_screen() > main_script.plank_limit) {
destroy_plank(); //Delete Oldest Planks
}
}
}
}
Main.dec_plank_in_hand()
public void dec_plank_in_hand() {
--planks_in_hand;
}
Your answer
Follow this Question
Related Questions
bullet holes parenting 1 Answer
how to Import unity3d project to an existed ios native app 0 Answers
SPACE SHOOTER SHOOTING SHOTS TUTORIAL HELP (UNITY 5 C#) 3 Answers
Referencing the Transform of the children of an Instantiated GameObject _PLEASE HELP!!! 1 Answer
Instantiate Object in camera View 0 Answers