Button thats is an object scrip help

Hello

I need help, i would like to have an object (cube or something i made in another 3D program) to be a button so it activates a animation, so when something hits the button which could be an object like a cube or something i made earlier it activates the animation you see what i mean what i would like to happen in this video Robot Wars House Robot Rebellion with Squirmin Vermin - YouTube go to 2:00-2:05

Please help

Thank you

3 Answers

3

There’s a few ways you could do this with colliders or triggers. I’ll outline one way:

  1. Attach a collider to your “Button”
  2. Enable the collider to be a trigger
  3. Drop this script onto your Button. I’ll do an example in JS:

var objectOfAnimation : GameObject; // Drag your object with the animation into this slot in the inspector

function OnTriggerEnter(other : Collider) {

if (other.tag == "whatever object you define that enters the trigger to play the animation") {

objectOfAnimation.animation.Play("theAnimation"); }
}

Should be other.collider.gameObject.tag :P

@stingman it dosent work :( still wont desend

post your code and I'll help you fix it

var objectOfAnimation : GameObject; // Drag your object with the animation into this slot in the inspector

function OnTriggerEnter(other : Collider) {

if (other.tag == “untitled”) {

objectOfAnimation.animation.Play(“pit 2”); }

}

Still not working :( all i want is a flat pannel to desend when something touched the button with the same texture as the pit in the video

ok the script does work correctly. I just created a simple scene to test it and it works fine. Toss me your email address and I'll send you a package to install to show you exactly how it works. All you have to do is import the package and load the scene titled :"Animationexample." once you do that just move the character into the button trigger and watch the other object animate. Give me your email address and I'll send you the package.

Also what are you using to activate the trigger? I forgot to mention that is the game object that needs to be tagged for the script to work. What this script is doing is saying : When an object with the tag : "untitled" (or whatever you call it) enters the trigger then the object defined as the variable "objectOfAnimation" will play the animation "pit 2". Also make sure you spell the animation exactly in the script as it's listed in your assets. If you still can't get it working send me your email.

im just using a Cylinder and my email is dalekandjedo@gmail.com

@Stingman hey, I need the files again hehe sorry new computer and my email deleted them same email so if you could send them again i would be very greatful

var objectOfAnimation : GameObject; // Drag your object with the animation into this slot in the inspector

function OnTriggerEnter(other : Collider) {

if (other.tag == “untitled”) {

objectOfAnimation.animation.Play(“pit 2”); }

}