• 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
Question by StigC · Mar 09, 2014 at 06:59 PM · cameracollisiontaggameobjectsfindgameobjectswithtag

OnTriggerEnter only if two tags are found?

Hi there.

I have a script attached to my camera that enables me to rotate it around my Player when pressing either z or x. However, I need the keys only to be enabled when the player enters a certain collider tag (called rotateZone atm.).

I've searched and tried several solutions, but the OnTriggerEnter wont trigger for me. I guess the issue is that the camera never enters the trigger, only the player does. But the camera is attached to the player object, so this ought to not be the problem.

So the question is:

In my CameraRotator script, with the use of OnTriggerEnter/Exit, how do I check if a gameobject with the tag "Player" has entered the trigger/collider of a gameobject with the tag "rotateZone"? Should I use FindGameObjectsWithTag?

Here's the script attached to the camera. I've removed the current tag and collider solutions I've been using, since they aren't working.

Any help would be appreciated :)

CameraRotator

 using UnityEngine;
 using System.Collections;
 
 public class CameraRotator : MonoBehaviour 
 {
     public float rotateTime = 1.0f;
     
     private bool _isTweening = false;
     private CrunchPlatformColliders _cruncher;
     private DisablePlayer _disablePlayer;
     
     void Start () 
     {
         _cruncher = GetComponentInChildren<CrunchPlatformColliders>();
         GameObject player = GameObject.FindGameObjectWithTag("Player");
         _disablePlayer = player.GetComponentInChildren<DisablePlayer>();
     }
     
     void Update () 
     {
         
         if (Input.GetKeyDown(KeyCode.Z))
         {
             rotateTween(90);
         }
         
         if (Input.GetKeyDown(KeyCode.X))
         {
             rotateTween(-90);
         }
     
     }
     
     private void rotateTween(float amount) 
     {
         if (_isTweening == false) 
         {
             _isTweening = true;
 //            _cruncher.setPlayerPos();
             _disablePlayer.disable();
             Vector3 rot = new Vector3(0,amount, 0);
             iTween.RotateAdd(gameObject, iTween.Hash(iT.RotateAdd.time, rotateTime, iT.RotateAdd.amount, rot, iT.RotateAdd.easetype, iTween.EaseType.easeInOutSine, iT.RotateAdd.oncomplete, "onColorTweenComplete"));
         }
     }
     
     private void onColorTweenComplete()
     {
         _isTweening = false;
         _disablePlayer.enable();
         _cruncher = GetComponentInChildren<CrunchPlatformColliders>();
         _cruncher.crunchCollidersToPlayer();
     }
 }
Comment

People who like this

0 Show 0
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

1 Reply

· Add your reply
  • Sort: 
avatar image

Answer by getyour411 · Mar 09, 2014 at 07:03 PM

On the gameobject rotateZone add this to script

    OnTriggerEnter (Collider other) {
     if (other.tag == "Player") {
     // do stuff
     }
     }
Comment

People who like this

0 Show 0 · 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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

21 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

Related Questions

How To Select Single Object From All Objects We Found Whit Tag? 1 Answer

Accessing all GameObjects with a certain tag 1 Answer

2D Camera Collision 1 Answer

3rd Person camera collision 2 Answers

Tags not working 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