Problem with collisions?

Hi. Basicly, I have this script thats supposed to open a CD case when a player hits it, but is not working…:

var smash : AudioClip;

function OnControllerColliderHit(hit:ControllerColliderHit)
{
	if (hit.gameObject.tag == "ObjectInteract") {
		CDSmash();
	}
}

function CDSmash()
{
	var cDCase = gameObject.FindWithTag("ObjectInteract");
	cDCase.animation.wrapMode = WrapMode.Loop;
	animation.Play("Open");
	audio.PlayOneShot(smash);
}

ObjectInteract is a tag I made and applied to the character… The console reports no bugs, however, this script does not work for some reason… anyone know why? :?

What do you mean? Is there some kind of a coding difference in 2.5 to 2.6?

No, that’s a spam bot. Just take a look at the links in the profile and it’s obvious. It takes common responses and word phrases and uses them in a way that attempts to mirror real sentences.

The first thing that comes to mind is that the collision hits something without the tag or isn’t registering. Try adding Debug.Log(hit.gameObject.tag); to the OnCollision function. If the hit is registering, it’ll print. If it prints, you can check to see if the tag matches or not.

Ok, I will when I get back home…

Spam bot? Are you serious? Seams like it made some sense, but I dont think Unity would change all the code every relese… Weird… Doesent the sign up page have that number-verification thing so that spam bots dont do that? :smile: LOL

Oh, dude, I figured it out- the script had to be attached to the character controller, and the object tagged “ObjectInteract” for it to work- but now I’m gonna add a boolean so the sound can only be played once…

YEA! GOT IT!

var hit : AudioClip;
var play : boolean = true;

function OnControllerColliderHit(hit:ControllerColliderHit)
{
	if (hit.gameObject.tag == "ObjectInteract") {
		ObjectPlay();
	}
}

function ObjectPlay()
{
	var object = gameObject.FindWithTag("ObjectInteract");
	if (!object.animation.isPlaying  play) {
	object.audio.PlayOneShot(hit);
	object.animation.wrapMode = WrapMode.Once;
	object.animation.Play("Open");
	play = false;
 }
}

I read Chapter 4 of ‘Unity Game Development Essentials’ today, it helped, man I so want that book… So all I have to do now is attatch the script to the character, then set the audio clip in the inspector, then add a ‘ObjectCollision’ tag to the case, and an audio component, and boom, it works! Thanks will! :smile: :smile: :smile: