Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by buzgata · Sep 16, 2016 at 06:42 AM · booleanboolcodepagebooleansgenerator

Building a Face Generator, need to destroy previous instance after pressing key a second time

I am building a Face Generator, everything works fine but my problem is that every time I press Space Bar it makes the randomized elements appear on top of one another, I need a way to destroy the previous face once the key is pressed a second time to generate a new one. I'm not sure how to proceed!! Thanks for the help!!

Code:

 using UnityEngine;
 using System.Collections;
 
 public class GeneratorScript : MonoBehaviour {
     public Transform spawnhats;
     public Transform spawnfaces;
     public Transform spawneyes;
     public Transform spawnmouths;
     public Transform spawnbackgrounds;
     public GameObject [] eyes;
     public GameObject [] hats;
     public GameObject [] faces;
     public GameObject [] backgrounds;
     public GameObject [] mouths;
     private bool faceAppeared;
 
 
     // Use this for initialization
     void Start () {
 
         faces[0]=GameObject.FindGameObjectWithTag("face1");
         faces[1]=GameObject.FindGameObjectWithTag("face2");
         faces[2]=GameObject.FindGameObjectWithTag("face3");
         faces[3]=GameObject.FindGameObjectWithTag("face4");
 
 
         eyes[0]=GameObject.FindGameObjectWithTag("eyes1");
         eyes[1]=GameObject.FindGameObjectWithTag("eyes2");
         eyes[2]=GameObject.FindGameObjectWithTag("eyes3");
         eyes[3]=GameObject.FindGameObjectWithTag("eyes4");
 
         hats[0]=GameObject.FindGameObjectWithTag("hats1");
         hats[1]=GameObject.FindGameObjectWithTag("hats2");
         hats[2]=GameObject.FindGameObjectWithTag("hats3");
         hats[3]=GameObject.FindGameObjectWithTag("hats4");
 
         backgrounds[0]=GameObject.FindGameObjectWithTag("back1");
         backgrounds[1]=GameObject.FindGameObjectWithTag("back2");
         backgrounds[2]=GameObject.FindGameObjectWithTag("back3");
         backgrounds[3]=GameObject.FindGameObjectWithTag("back4");
 
         mouths[0]=GameObject.FindGameObjectWithTag("mouths1");
         mouths[1]=GameObject.FindGameObjectWithTag("mouths2");
         mouths[2]=GameObject.FindGameObjectWithTag("mouths3");
         mouths[3]=GameObject.FindGameObjectWithTag("mouths4");
 
 
 
 
     }
 
     // Update is called once per frame
     void Update () {
 
 
 
         if (Input.GetKeyDown ("space")){
 
             faceAppeared = true;
             Instantiate (faces[Random.Range(0,faces.Length)], spawnfaces.position, spawnfaces.rotation);
             Instantiate (eyes[Random.Range(0,eyes.Length)], spawneyes.position, spawneyes.rotation);
             Instantiate (hats[Random.Range(0,hats.Length)], spawnhats.position, spawnhats.rotation);
             Instantiate (backgrounds[Random.Range(0,backgrounds.Length)], spawnbackgrounds.position, spawnbackgrounds.rotation);
             Instantiate (mouths[Random.Range(0,mouths.Length)], spawnmouths.position, spawnmouths.rotation);
         }
 
     }
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

69 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I check if bool is true from another script? 2 Answers

If statement not working 1 Answer

Call a function When a bool changes value? 2 Answers

Trying to establish turn order in my game but bool will not toggle properly 0 Answers

Boolean somehow becomes false. And an Integer zero. 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges