- Home /
Set asset as weapon with animation and destroying other assets on impact
I'm an art student who's new to Unity and I thought I'd make my first project for a senior thesis class. The project is due when we come back from the weekend but google + the unity site have not been useful. I've been trying to find what I need for weeks. Any time I find a lead or code that should work it doesn't or I'm not sure where to put it. I have minimal coding experience. Simpler code and showing me where to put it is much appreciated. I still have a lot of other homework to do and I don't want my entire weekend going to this.
The game is of a pretend art gallery I've compiled in to Unity. The different artworks are .fbx, .obj, .blend, and .3ds (only one of these) files. I have the first person controller module with a child model called umbrellawanimation.blend. As the name says there is an animation on it I managed to import, but can't get to work. This animation is for the umbrella to swing like a sword, and I want it to play on the left mouse click.
I want to use the umbrella to destroy the artworks it encounters, touches, or collides with. A particle emit or explosion would be an added bonus. So far the umbrella only goes through everything or starts veering off in some random direction. I think I read somewhere I can do an OnCollission code and sort all of the artwork by a tag. This doesn't seem to work or I'm missing a component of either the artwork or the umbrella. As far as I know I've set some form of a collider and a rigidbody on everything.
I was using the script provided in the learning area modified to fit my game. What I have below was added to my umbrella as a script component.
#pragma strict
function OnCollisionEnter (col : Collision)
{
if(col.gameObject.tag== "Artpiece")
{
Destroy(col.gameObject);
}
}
Whoever can help me get this done in time would be my hero! If anyone can also direct me to something about proximity specific audio (audio only starts within a certain distance of an object and can only be heard in that area), that would be awesome! In the mean time I'll keep trying and work on a menu and such. I want this playable before I mess with extras. I apologize for asking for so much in so little time. I'm hoping when I try another game I'll learn from this one and spend more time on it.
I'm using version 4.2.2
Update!
I managed to get the destroy on collision to work! I set my umbrella as the trigger and worked a destroy on collision entry code from a site example. I may fiddle with a delay if I have time after audio.
Here's the code I implemented. I put it on my umbrella (tagged: weapon). Any work I wanted destroyed (which included defaults and all components was labeled Artpiece)
var thing : GameObject;
function OnTriggerEnter (other : Collider) {
if( other.gameObject.CompareTag ("Artpiece" ))
{
Destroy(other.gameObject);
}
}