Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 UTeam · Apr 01, 2014 at 04:55 PM · collisioncharacter

Multiple colliders (triggers) in same script?

Hi all, I am working on a project that involves the character experiencing events when entering colliderboxes. The colliderboxes are triggers that send an int over UDP protocol.

My objective is to have 5 colliderboxes that each sends an int if the character enters the colliders.

I am, however, not very successful, and I need immediate assistance, as I am not as good in programming as the majority in the forums. This is my script:

using UnityEngine; using System.Collections; using System; using System.Text; using System.Net; using System.Net.Sockets; using System.Threading; using System.Collections.Generic;

public class NickThesisTriggerManager : MonoBehaviour { private static NickThesisTriggerManager instance;
public static int SendValue1 = 20; public static int SendValue2 = 30;

     // Use this for initialization
     void Start () {
             instance = this;
             init (); 
     }


     // Triggers are placed on the collider boxes
     void OnTriggerEnter(Collider other){
         if (GameObject.Find("Trigger1") != true)
         {
             return;
         }
         else
         {
             Debug.Log("PLAYER HAS ENTERED TRIGGER 1");
             SendUDPMessage(SendValue1);
         }
         if (GameObject.Find("Trigger2") != true)
         {
             return;
         }
         else
         {
             Debug.Log("PLAYER HAS ENTERED TRIGGER 2");
             SendUDPMessage(SendValue2);
         }
     }


alt text

untitled-1.png (90.8 kB)
Comment
Add comment · Show 3
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 Slobdell · Apr 01, 2014 at 05:06 PM 0
Share

What's the question

avatar image Slobdell · Apr 01, 2014 at 05:11 PM 0
Share

Oh boy.....is this a school project? When the collider enters all you're doing is calling gameobject.find, which returns a gameobject not a Boolean. So it will always not equal true and send the message. You need to get the gameobject info out if the collider called other and detect which object it is

avatar image UTeam · Apr 02, 2014 at 09:54 AM 0
Share

Thanks, I figured it out ;) Yes, this is a school project.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by koray1396 · Apr 01, 2014 at 05:12 PM

I think you want something like this;

     void OnTriggerEnter(Collider other){
         if(other.transform.name == "Trigger1"){
             Debug.Log("PLAYER HAS ENTERED TRIGGER 1");
             SendUDPMessage(SendValue1);
         } else if(other.transform.name == "Trigger2"){
             Debug.Log("PLAYER HAS ENTERED TRIGGER 2");
             SendUDPMessage(SendValue2);
         }
     }
Comment
Add comment · Share
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

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

22 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

Related Questions

Terrain, Player falls through.... but only some parts. 0 Answers

collision detection not working? 1 Answer

High speed and collisions: Character Controller falls through the ground when jumping\running at a certain speed 0 Answers

gameobject destroyed on collision with character 3 Answers

Simple AI and Animation 2 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