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 bnok · Apr 13, 2019 at 08:57 PM · script.reference

script doesnt go off when its called

so im making kinda of an endless runner and i have object that gives "powerups " but when i hit one of the objects it doesnt trigger the effect its needed to do , this is the script of the objects that gives powerups private void OnTriggerEnter(Collider other) {

         if (gameObject.layer == 9)
         {
             
             gameSession.AddToScore(10f);
             Destroy(gameObject);
             
         }
         else if (gameObject.layer == 10 )
         {
 
             gameSession.getPlayer().GetComponent<Player>().StartSlowingSpeed();
             Destroy(gameObject);
         }
         else if (gameObject.layer == 11)
         {
             Destroy(gameObject);
             gameSession.getPlayer().GetComponent<Player>().StartFloating();
         }
         
         
     }

i have a problem a problem in the ones with layer = 10,11

 public void StartSlowingSpeed()
     {
         Debug.Log("step 2 done ");
         StartCoroutine(SlowSpeed());
     }
 
     IEnumerator SlowSpeed()
     {
         addedSpeed -= playerSpeed / 2;
         yield return new WaitForSeconds(slowSpeedTime);
 
 
         addedSpeed = 0;
 
     }
 
     //grape eaten 
 
     public void StartFloating()
     {
         StartCoroutine(FloatUp());
     }
 
     IEnumerator FloatUp()
     {
         jumpMem += 5f;
         //gameObject.transform.Translate(Vector3.up * Time.deltaTime * floatHeight);
         yield return new WaitForSeconds(jumpHeight);
         jumpMem = 0;
         yield return new WaitForSeconds(floatTime);
         jumpMem -= 5f;
         //gameObject.transform.Translate(Vector3.up * Time.deltaTime * -floatHeight);
         
      }

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 highpockets · Apr 13, 2019 at 09:47 PM 0
Share

I think you mean to check other.gameObject.layer in your OnTriggerEnter code. What you are doing now is checking if the gameObject that this trigger script is attached to is on layer 9, 10 or 11, you are not checking the “other” collider which I assume are power ups.

avatar image Bunny83 highpockets · Apr 14, 2019 at 12:33 AM 0
Share

I don't think that's the issue since he actually destroys the object this script is attached to. So this is most likely his powerup script. However since he uses different layers it's possible that there may be no collisions between the involved layers. Though it's hard to tell from the information given in the question. We can't do any active debugging. A simple Debug.Log("Powerup pickup. Layer=" + gameObject.layer); at the beginning of "OnTriggerEnter" should already help to figure out what is happening.

avatar image highpockets Bunny83 · Apr 14, 2019 at 06:45 AM 0
Share

Oops, ya, I failed to notice the gameSession.getPlayer().GetComponent().StartFloating();... But I do see that this line is after you destroy the game object, thus the line will have no effect on the player. You should put it before you destroy the object.

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.

Follow this Question

Answers Answers and Comments

112 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Easily reference class instance 1 Answer

Identifying the attacker in multiplayer 0 Answers

Is constantly referencing or defining once then changing better 1 Answer

How to reference a prefab to the script that doesn't exist in Hierarchy 0 Answers

script type variables 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