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 3eBpA · Feb 07, 2014 at 06:34 PM · rigidbodytriggercube

Trigger problem

Hello guys, I've got a problem with trigger, here it's code : using UnityEngine; using System.Collections;

 public class Trigger : MonoBehaviour {
 
     public AudioClip watersound;
     private bool InWater;
 
     // Use this for initialization
     void Start () {
 
     }
     
     // Update is called once per frame
     void Update () {
         
     }
 
     public void OnTriggerEnter(Collider other){
         if(other.tag == "Water" && Camera.main.audio.isPlaying != true)
         {
             Camera.main.audio.clip = watersound;
             Camera.main.audio.Play();
             PlayerScript.Pspeed = 0.007f;
             InWater = true;
         }
         else if(other.tag == "Ground" && Camera.main.audio.isPlaying != true)
         {
             InWater = false;
             PlayerScript.Pspeed = 0.016f;
         }
     }
 }

the trigger should make player speed slower when it touch the blue square, but it doesn't do that, I can say better, it's do nothing =/, here're some screens : how can u see, there's a trigger

and another screen, all squares have got a rigidbody attached here's the 2nd screen

1.png (201.2 kB)
2.png (130.4 kB)
Comment
Add comment · Show 4
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 supernat · Feb 07, 2014 at 06:44 PM 0
Share

First, if you haven't already, try putting Debug.Log() statements in your trigger cases to make sure you aren't missing something logical on your end, then let us know if you are still stumped. If you already did that, is the script entering the code you think it should?

avatar image 3eBpA · Feb 08, 2014 at 05:16 PM 0
Share

well, the problem is that trigger works only once, on Initialization, but all cubes have got collider and rigidbody, so idk where the problem is

avatar image 3eBpA · Feb 08, 2014 at 05:20 PM 0
Share

well, I found one thing, when I enable physics, trigger works as it should but what should I do with static objects ? =\

avatar image 3eBpA · Feb 08, 2014 at 05:22 PM 0
Share

YEEESSS, I HAVE FIND THE SOLUTION :D, it is : enable physics and freeze position, thank u guys for help

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Nanobrain · Feb 07, 2014 at 07:27 PM

It could be because this line is evaluating to 'false':

 if(other.tag == "Water" && Camera.main.audio.isPlaying != true)

Change that to:

 if(other.tag == "Water")

And see if it works now. I'm not sure what purpose you are evaluating the sound playing, but I think this is your key. That is, unless it in your player movement code.

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 3eBpA · Feb 07, 2014 at 08:21 PM 0
Share

Oh, thanks man, I'll try this in some hours but also very thanks for your help :3

avatar image
0

Answer by 3eBpA · Feb 08, 2014 at 05:52 PM

oh, Nanobrain, your idea don't works, trigger still doesn't make anything =\

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

20 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

Related Questions

Pinwheel prevents player by moving 0 Answers

Rigidbody + Multiple Trigger Colliders - OnTriggerEnter - Get which Collider triggered the event issue 1 Answer

On Collide script not working! 1 Answer

Check for rigidbody presence when in collision with a trigger 2 Answers

Can a object without a rigidbody be triggered by a trigger? 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