• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by agent007jk · Sep 20, 2017 at 02:50 PM · triggertriggering animation box collider

How do I trigger my animation with a cube(collider) and a triggerplatform (triggerzone)?

I have no ideer how to fix this. What I want, is my dooranimation to play (open) when my cube collider enters this squared triggerzone i have created. And yes, I have marked my triggerzone, "Is trigger". In the picture below is my animator setting for my "Platformtrigger"- animatorcontroller. I assumed that i needed a boolean parameter to make something trigger, so i have a bool called, "Play", and it's set to false. Hopefully there's a kind soul out there who would like to help me. I would really really appreciate it, since i have been stuck with this for a while.

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class PlatformTrigger : MonoBehaviour { private Animator animator; public bool Play; public Animation DoorOpen;

 void Start()
 { 
      //DoorOpen = GetComponent<Animation> ();
     animator.enabled = true;
     animator.SetBool ("Play", false);
     Debug.Log ("It works!");
 }

 void OntriggerStay(Collider Cube)
 {
     if (Cube.gameObject.tag == "Cube") {
         animator.SetBool ("Play", true);
         Debug.Log ("TriggerStay doesn't work");
         //DoorOpen.Play ("DoorOpen");
     //} else {
         //animation.Play ("DoorOpen" = false);
 }

     


     }
 }



alt text

alt text

udklip.jpg (189.0 kB)
udklip-2.jpg (211.8 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by NinjaEntertainment · Sep 20, 2017 at 04:24 PM

Hi there! I don't use animators to play animation on trigger. I play animation in a script. here is code:

     using System.Collections;
     using System.Collections.Generic;
     using UnityEngine;
     
     public class YOUR SCRIPT NAME : MonoBehaviour { //dont forget to change this to your script name
     
         public Animation anim;
         void Start () {
             anim = GetComponent<Animation> ();
         }
         
         // Update is called once per frame
         void OnTriggerEnter(Collider other) {
 if(Input.GetKeyDown(KeyCode.E))
 {
                 anim.Play ("YOUR ANIMATION NAME");//here you place animation name :D
             }
         }
     }

when you save the script make an cube and place it close to door. Untick Mesh renderer and set box collider to is trigger. Expand box collider if u need as well. You can also put text when you walk to trigger and it show up saying "Press E to open door " and when you press E door play animation Open or whatever...When you put script to a trigger(gameobject or cube whatever) you put animation component and put your animation onto it. and put animation on a script. Sorry for my English if you don't understand anything ask i will respond you quickly or i will make a project for you and send you via this forum :D Best Regards :D -Ninja Entertainment

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

83 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can't click gameobject when over another trigger? 1 Answer

Animation in unity 2 Answers

OnTriggerExit2D not working, but OnTriggerEnter2D does??? 5 Answers

My animation plays before triggered 2 Answers

Collide with object trigger - why animation only occurs on first encounter with trigger 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges