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 /
  • Help Room /
avatar image
0
Question by Razputin · Nov 09, 2015 at 09:01 PM · collisioncollidertagtags

Need Help With Collider Script.

This script is missing some stuff because i've been deleting and changing things so if something isn't being used just ignore it for now but my question is why are my Debugs not working. The arrow gameobjects are clearly passing through the triggers but nothings happening.

This script is placed on Arrows which then move up through triggers.

 using UnityEngine;
 using System.Collections;
 
 public class RhythmGameArrows : MonoBehaviour {
 
     public float moveSpeed = 2.5f;
     public GameObject thisArrow;
     public AudioClip chime;
 
     void Start()
     {
         thisArrow = this.gameObject;
     }
 
     void Update () 
     {
         transform.Translate(Vector3.up*moveSpeed * Time.deltaTime, Space.World);
         StartCoroutine(kill ());
     }
 
     void OnTriggerStay(Collider other)
     {
         if(other.tag == "farLeftCatcher" && thisArrow.tag == "leftArrow")
         {
             Debug.Log("Hit");
             if(Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.LeftArrow))
             {
                 good ();
             }
         }
         else if(other.tag == "leftCatcher" && thisArrow.tag == "upArrow")
         {
             Debug.Log("Hit");
             if(Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.UpArrow))
             {
                 good ();
             }
         }
         else if(other.tag == "farRightCatcher" && thisArrow.tag == "rightArrow")
         {
             Debug.Log("Hit");
             if(Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.RightArrow))
             {
                 good ();
             }
         }
         else if(other.tag == "rightCatcher" && thisArrow.tag == "downArrow")
         {
             Debug.Log("Hit");
             if(Input.GetKeyDown(KeyCode.S) || Input.GetKeyDown(KeyCode.DownArrow))
             {
                 good ();
             }
         }
 
     }
     void good()
     {
         GetComponent<AudioSource>().PlayOneShot(chime);
         PlayerPrefs.SetInt("Cash", PlayerPrefs.GetInt("Cash") + 1);
         Destroy(gameObject);
     }
 
     private IEnumerator kill()
     {
         yield return new WaitForSeconds(2);
         Destroy(gameObject);
     }
 }
 
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by OncaLupe · Nov 09, 2015 at 10:13 PM

Make sure you have a Rigidbody on the arrows, otherwise there's no physics happening for the colliders to trigger from. You can also add a Debug.Log(other.tag) to the top of the OnTriggerStay() method to make sure it's at least seeing something.

A few other things:

The thisArrow variable is redundant since you can just use gameObject.tag.

The StartCoroutine() should be in the Start() method so it's not getting started every frame. An alternative is to do this in Start():

 Destroy(gameObject, 2f);

This will destroy the object after 2 seconds without needing a separate method.

Comment
Add comment · Show 1 · 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 Razputin · Nov 09, 2015 at 10:18 PM 0
Share

Thanks I fixed it already. No Rigidbodys was the answer though.

avatar image
0

Answer by MalachiteBR · Nov 09, 2015 at 09:08 PM

Make sure you are using the right tags on the triggers and on the arrow.

Suggestions:

Instead of doing this (other.GetComponent().tag ) several times you should just call other.tag, because other is already a collider.

Instead of doing if, if, if, if... you should use if, else if, else if... Unless it is possible to enter all the ifs on just one loop.

And try to respect the naming conventions, a method named good isnt a good approach.

Comment
Add comment · Show 1 · 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 Razputin · Nov 09, 2015 at 09:19 PM 0
Share

makes it more efficient but doesn't fix the problem, my tags appear to be correct.

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

37 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

Related Questions

How to make a growing mesh 0 Answers

How To Ignore A Tag 1 Answer

Multiple colliders index problem,i have multi colliders, which collider is my? 2 Answers

Usage of multiple tags or some other workaround? 1 Answer

How to make OnTriggerEnter Only work for certain Gameobjects? 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