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 /
avatar image
0
Question by Matasiethe · Mar 21, 2017 at 03:21 AM · prefab-instance

Change one intance, change all the prefab - Not found the correct answer in other threads

I'd read some similar questions, but no one help me. I have a prefab that instanciate regular times, when I click over a singular prefab, the gameobject turn green, change a bool and play an animation. The problen is that all the prefab made these three things. What can I do? This is the script of the instance:

 public class GameManager : MonoBehaviour
 {
     
     public GameObject [] piso; //prefab cuadrado
     public GameObject cuadrados; //gameobject para poner los cuadrados generados
     public float medidaZ = 50f; //medida para agregar el otro cuadrado
 
     private int contador = 0; //contador de cuadrados
     private GameObject pisos;
     
 
 
     // Use this for initialization
     void Start ()
     {
         GenerarCuadrados();
         GenerarCuadrados();
         GenerarCuadrados();
         GenerarCuadrados();
         GenerarCuadrados();
     }
 
 
     public void GenerarCuadrados()
     {
         pisos = Instantiate(piso[Random.Range(0, piso.Length)], new Vector3(transform.position.x, transform.position.y, medidaZ), transform.rotation) as GameObject;
         pisos.transform.SetParent(cuadrados.transform);
         pisos.name = (contador + 1).ToString();
         contador++;
         
         medidaZ = transform.position.z + medidaZ + 10f;
     }
 }

And this is the script of the prefab:

 {
     private bool controlClick; //bool para controlar si el jugador hizo click en el cuadrado.
 
     public Material material; //variable para cambiar el color del cuadrado cuando se toque. 
     public Material materialInicial; //variable con el color inicial
     public AudioSource sonidoAltocar; //sonido cuando tocas el cuadrado y se vuelve verde.
 
     private bool cuadradoVerdeOK = false;     //bool para saber si se toco el cuadrado y se volvio verde
     public Animator anim;      //animacion de que gira el piso cuando es tocado
 
     private GameObject[] piso;
 
     void Start()
     {
         material = new Material(material);
         cuadradoVerdeOK = false;   //empieza siempre en falso, no es verde.
         gameObject.GetComponent<MeshRenderer>().material = materialInicial;
         controlClick = false;
     }
 
     void Update()
     {
         //cuando toca el cuadrado este cambia el color y suena
         if (Input.GetMouseButton(0) && !cuadradoVerdeOK)
         {
              anim.Play("clickPiso");
               GetComponent<MeshRenderer>().material = new Material(material);
               sonidoAltocar.Play();
              cuadradoVerdeOK = true;
           controlClick = true; //indica que el jugador ha hecho click
         }
     }


Comment
Add comment · Show 1
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
avatar image Matasiethe · Mar 23, 2017 at 08:18 AM 0
Share

Anyone can help me?

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Why can't I undo changes to a prefab? (or to an instance of it after I apply the changes) 1 Answer

Unity 2D Game Issue: Script is only affecting one prefab instead of all of them. 0 Answers

How to undo prefab Apply? 0 Answers

I need to move a clone of a prefab to a specific position after it instantiates 1 Answer

How do I get the Player's Health Script as Component? 1 Answer


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