sorry about the title, I’m not sure how to specify it in there alone.
I have narrowed the problem down to:
if (hit.collider.gameObject.layer == "WestWallTrigger"){
Instantiate(myBullet, hit.point, Quaternion.Euler(Vector3(180, 0, 0)));
}
anything i put within those brackets just won’t trigger, and I’ve no idea why. it doesn’t matter what layer I use, I’ve tried several, the script just won’t continue to, in this case, instantiate at the hit point. Do any of you know why?
layer is an int (not a string.) Look up which layer WestWallTrigger is on and use that number in your ==.
May as well write the suggested debug lines in the other reply, just to show that. Are you using javascript? In C#, a compile error would pop up: “cannot convert string to int.” Maybe #pragma strict in unityscript would also give that. Helps find lots of errors quickly.
Add a couple of Debug.Log
messages before the if
statement.
Debug.Log("Layer=" + hit.collider.gameObject.layer);
Debug.Log("Name=" + hit.collider.gameObject.name);
What does it show? Odds are the layer isn’t equal to “WestWallTrigger”, so the if
conditional evaluates to false, which means the code inside the brackets doesn’t execute.
What is the context of this code? Have you done a Raycast
? If your log messages don’t display, that means the function this code is in isn’t being called, or there’s a previous if
conditional that’s evaluating to false.