- Home /
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 :
and another screen, all squares have got a rigidbody attached
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?
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
well, I found one thing, when I enable physics, trigger works as it should but what should I do with static objects ? =\
YEEESSS, I HAVE FIND THE SOLUTION :D, it is : enable physics and freeze position, thank u guys for help
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.
Oh, thanks man, I'll try this in some hours but also very thanks for your help :3
Answer by 3eBpA · Feb 08, 2014 at 05:52 PM
oh, Nanobrain, your idea don't works, trigger still doesn't make anything =\