Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 awplays49 · Mar 29, 2015 at 10:38 PM · instantiatebuttondestroyaddsubtract

Mouse Methods (OnMouseDown, OnMouseOver etc) stop working after certain circumstances

in my game you can move on units, and nothing in between.

you can also right click blocks to delete them.

there is also another way to do this, by hitting the - button, but that just deletes the current block.

when i delete the current block by right click, then add it back with the + button, that new block ignores mouse functions.

cube script:

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 
 public class Cube : MonoBehaviour {
     
     public GameObject CubeManagerGet;
     public GameObject AddButtonGet;
     public GameObject SubtractButtonGet;
     public Text TextGet;
     public int DataValue;
     public bool CanSubtract;
 
     void Start () {
         CubeManagerGet.GetComponent <CubeManager> ().Cubes.Add (gameObject);
         DataValue = CubeManagerGet.GetComponent <CubeManager> ().Cubes.Count - 1;
         if (AddButtonGet.GetComponent <ActionButton> ().HasReset == true)
         {
             CubeManagerGet.GetComponent <CubeManager> ().CurrentCube = DataValue;
             AddButtonGet.GetComponent <ActionButton> ().HasReset = false;
         }
         if (DataValue == 0)
         {
             GetComponent <SpriteRenderer> ().color = Color.red;
             GetComponent <SpriteRenderer> ().sortingOrder = 2;
         }
         else
         {
             GetComponent <SpriteRenderer> ().color = Color.black;
             GetComponent <SpriteRenderer> ().sortingOrder = 1;
         }
         gameObject.name = "Cube (" + DataValue + ")";
     }
 
     void Update () {
         Debug.Log (CanSubtract);
         if (CubeManagerGet.GetComponent <CubeManager> ().CurrentCube == DataValue)
         { 
             GetComponent <SpriteRenderer> ().sortingOrder = 2;
             GetComponent <SpriteRenderer> ().color = Color.red;
             TextGet.text = "Coordinates: {" + transform.position.x + ", " + transform.position.y + "}";
             TextGet.color = Color.green;
         }
         else
         {
             GetComponent <SpriteRenderer> ().sortingOrder = 1;
             GetComponent <SpriteRenderer> ().color = Color.black;
         }
         if (CanSubtract == true && Input.GetMouseButton (1) && CubeManagerGet.GetComponent <CubeManager> ().Cubes [CubeManagerGet.GetComponent <CubeManager> ().CurrentCube] != null && CubeManagerGet.GetComponent <CubeManager> ().CubeCount > 1)
         {
             if (CubeManagerGet.GetComponent <CubeManager> ().CurrentCube == DataValue)
             {
                 TextGet.text = "No Cube Selected";
                 TextGet.color = Color.red;
             }
             Destroy (gameObject);
         }
         if (Input.GetKey (KeyCode.LeftShift) && CubeManagerGet.GetComponent <CubeManager> ().CurrentCube == DataValue && CubeManagerGet.GetComponent <CubeManager> ().Cubes [CubeManagerGet.GetComponent <CubeManager> ().CurrentCube] != null)
         {
             if (Input.GetKeyDown (KeyCode.W))
             {
                 Instantiate (gameObject, new Vector3 (transform.position.x, transform.position.y + 1, transform.position.z), Quaternion.identity);
             }
             if (Input.GetKeyDown (KeyCode.A))
             {
                 Instantiate (gameObject, new Vector3 (transform.position.x - 1, transform.position.y, transform.position.z), Quaternion.identity);
             }
             if (Input.GetKeyDown (KeyCode.S))
             {
                 Instantiate (gameObject, new Vector3 (transform.position.x, transform.position.y - 1, transform.position.z), Quaternion.identity);
             }
             if (Input.GetKeyDown (KeyCode.D))
             {
                 Instantiate (gameObject, new Vector3 (transform.position.x + 1, transform.position.y, transform.position.z), Quaternion.identity);
             }
         }
     }
 
     void OnMouseOver () {
         CanSubtract = true;
     }
 
     void OnMouseExit () {
         CanSubtract = false;
     }
 
     void OnMouseDown () {
         CubeManagerGet.GetComponent <CubeManager> ().CurrentCube = DataValue;
     }
 }

button script:

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 
 public class ActionButton : MonoBehaviour {
 
     public enum Actions {HorizontalNegative, VerticalNegative, HorizontalPositive, VerticalPositive, Add, Subtract};
     public Actions Action;
     public GameObject CubeManagerGet;
     public GameObject CubeToEdit;
     public Text TextGet;
     public bool HasReset;
     
     public void Interact () {
         CubeToEdit = CubeManagerGet.GetComponent <CubeManager> ().Cubes [CubeManagerGet.GetComponent <CubeManager> ().CurrentCube];
         if (Action == Actions.VerticalPositive)
         {
             CubeToEdit.GetComponent <Cube> ().transform.position += Vector3.up;
         }
         if (Action == Actions.HorizontalNegative)
         {
             CubeToEdit.GetComponent <Cube> ().transform.position += Vector3.left;
         }
         if (Action == Actions.VerticalNegative)
         {
             CubeToEdit.GetComponent <Cube> ().transform.position += Vector3.down;
         }
         if (Action == Actions.HorizontalPositive)
         {
             CubeToEdit.GetComponent <Cube> ().transform.position += Vector3.right;
         }
         if (Action == Actions.Add)
         {
             if (CubeManagerGet.GetComponent <CubeManager> ().Cubes [CubeManagerGet.GetComponent <CubeManager> ().CurrentCube] != null)
             {
                 Instantiate (CubeToEdit, CubeToEdit.transform.position, Quaternion.identity);
             }
             else
             {
                 for (int CubeCheck = 0; CubeCheck < CubeManagerGet.GetComponent <CubeManager> ().CubeCount - 1; CubeCheck ++)
                 {
                     if (CubeManagerGet.GetComponent <CubeManager> ().Cubes [CubeCheck] != null)
                     {
                         CubeToEdit = CubeManagerGet.GetComponent <CubeManager> ().Cubes [CubeCheck];
                         HasReset = true;
                         Instantiate (CubeToEdit, Camera.main.transform.position, Quaternion.identity);
                         break;
                     }
                 }
             }
         }
         if (Action == Actions.Subtract && CubeManagerGet.GetComponent <CubeManager> ().CubeCount > 1)
         {
             Destroy (CubeManagerGet.GetComponent <CubeManager> ().Cubes [CubeManagerGet.GetComponent <CubeManager> ().CurrentCube]);
             TextGet.text = "No Cube Selected";
             TextGet.color = Color.red;
         }
     }
 }


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 awplays49 · Mar 29, 2015 at 11:40 PM 0
Share

Just checked, and FYI the clones made that way do in fact have colliders.

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

20 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

Related Questions

Adding a life on collision, otherwise subtract 1 Answer

Instantiate prefab and Add to a Generic List 2 Answers

Proper/Best way to Instantiate and Destroy with Unity Networking? 2 Answers

instantiate,destroy,gain speed in time 2 Answers

Duplication(instance) re-create deleted children 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