• 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 josudl · Jan 29, 2017 at 12:19 PM · collidercolliderscollider2dstatic variable

Collider keypad

i'm making a keypad using GameObjects with Collider and this script;

using UnityEngine; using System.Collections;

public class button1 : MonoBehaviour {

 int chevron1;
 int chevron2;
 int chevron3;
 int chevron4;
 int chevron5;
 int chevron6;
 int chevron7;

 bool chevron1set;
 bool chevron2set;
 bool chevron3set;
 bool chevron4set;
 bool chevron5set;
 bool chevron6set;
 bool chevron7set;

 int[] Dial;

 void Start () {
     DHD.chevron1 = chevron1;
     DHD.chevron2 = chevron2;
     DHD.chevron3 = chevron3;
     DHD.chevron4 = chevron4;
     DHD.chevron5 = chevron5;
     DHD.chevron6 = chevron6;
     DHD.chevron7 = chevron7;

     DHD.chevron1set = chevron1set;
     DHD.chevron2set = chevron2set;
     DHD.chevron3set = chevron3set;
     DHD.chevron4set = chevron4set;
     DHD.chevron5set = chevron5set;
     DHD.chevron6set = chevron6set;
     DHD.chevron7set = chevron7set;

     DHD.Dial = Dial;
     Dial = new int[7] { chevron1, chevron2, chevron3, chevron4, chevron5, chevron6, chevron7 };

 }
 

 void OnMouseDown(){

     if (chevron1set == false) {
         chevron1 = 1;
         Debug.Log ("chevron 1 set");
         chevron1set = true;
     }
     else if (chevron1set == true && chevron2set == false) {
         int chevron2 = 1;
         Debug.Log ("chevron 2 set");
         chevron2set = true;
     }
     else if (chevron2set == true && chevron3set == false) {
         int chevron3 = 1;
         Debug.Log ("chevron 3 set");
         chevron3set = true;
     }
     else if (chevron3set == true && chevron4set == false) {
         int chevron4 = 1;
         Debug.Log ("chevron 4 set");
         chevron4set = true;
     }    
     else if (chevron4set == true && chevron5set == false) {
         int chevron5 = 1;
         Debug.Log ("chevron 5 set");
         chevron5set = true;
     }
     else if (chevron5set == true && chevron6set == false) {
         int chevron6 = 1;
         Debug.Log ("chevron 6 set");
         chevron6set = true;
     }
     else if (chevron6set == true && chevron7set == false) {
         int chevron7 = 1;
         Debug.Log ("chevron 7 set");
         chevron7set = true;
     }
 }

}

But it only works when i click on the same Collider all the times. How can I fix it to make it work when I click on different Colliders? Thank you

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Character Controller won't collide with anything 1 Answer

Is it possible to detect collisions between 2d and 3d objects? 2 Answers

how to snap objects by colliders2D ? 1 Answer

detect if collider is not touching anything 0 Answers

How to destroy player when collide with enemy? 3 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges