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 Shohre · Feb 22, 2019 at 05:39 AM · triggerstarget

OnTrigger does not work for multi targets

Hello. I am new to Unity. I am using Easy Ar multi-target tracker, and OnTriggerEnter does not work for me. I considered checking IsTrigger and having a rigid body. It is surprising that for a simple object like cube the OntriggerEnter works but for my multi-target, the OnTriggerEnter never called.

here is link of my project:

Pls, help me.

p.s. There may be a problem with the targets object like their shader directory, but I am not sure. When I move the character toward targets by tag, it moves but OnTriggerEnter does not work.

More Descriptions are as follows:

alt text

This is one of my targets tracked by an imageTracker.

alt text

And this is my character. both have rigid body , collider, and checked isTrigger.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class moveToTarget : MonoBehaviour
 {
     private float step;
     private GameObject[] tag1;
     private GameObject[] tag2;
     private bool hit1;
     private bool hit2;
 //    private bool hit3;
 
     // Start is called before the first frame update
     void Start()
     {
         hit1 = hit2 = false;
         step = 2f * Time.deltaTime;
         tag1 = GameObject.FindGameObjectsWithTag("tag1");
         tag2 = GameObject.FindGameObjectsWithTag("tag2");
 
     }
     private void OnTriggerStay(Collider other)
     {
         hit1 = true;
     }
     void OnCollisionEnter(Collision collision)
     {
         hit1 = true;
 
 
     }
         private void OnTriggerEnter(Collider other)
     {
         if (other.gameObject.tag == "tag1")
             hit1 = true;
         else if (other.gameObject.tag == "tag2")
             hit2 = true;
        // else if (other.gameObject.tag == "tag3")
          //   hit3 = true;
     }
 
     // Update is called once per frame
     void Update()
     {
          if (!hit2)
             transform.position = Vector3.MoveTowards(transform.position, tag2[0].transform.position, step);
 
          else if (!hit1)
          
            transform.position = Vector3.MoveTowards(transform.position, tag1[0].transform.position, step);
 
        
 
     }
 }

This is the script added to my character. The character movetoward target I mentioned, but the OnTriggerEnter never called.

screen-shot-2019-02-21-at-113113-pm.png (417.5 kB)
screen-shot-2019-02-21-at-113144-pm.png (402.1 kB)
Comment
Add comment · Show 2
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 zereda-games · Feb 22, 2019 at 06:12 AM 0
Share

sorry, but I need more details, code, and or images of the problem to help more.

avatar image Shohre zereda-games · Feb 22, 2019 at 06:41 AM 0
Share

@zereda-games I updated the problem.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Laiken · Feb 22, 2019 at 06:15 AM

Not sure I understood the problem, but make sure the object entering the trigger has a collider.

Comment
Add comment · Show 3 · 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
avatar image Shohre · Feb 22, 2019 at 06:27 AM 0
Share

Yes. both have colliders.

avatar image Shohre · Feb 22, 2019 at 06:28 AM 0
Share

The problem is OnTriggerEnter never is called when I put the breakpoint.

avatar image Shohre · Feb 22, 2019 at 06:41 AM 0
Share

I updated the problem.

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

102 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 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

What is the trigger? 2 Answers

Build and Run is breaking my triggers! 1 Answer

Some problems with triggers? 1 Answer

Need help with setting all items of a specific tag to "inactive" when i die. 1 Answer

Run a Prefab while ONLY in the trigger zone. 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