Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 ChoosingOwl · Nov 07, 2013 at 11:55 AM · animationcollisiontriggerraycasthitopen

Starting animation with collision

Im having trouble making this code work. Im no genius or experienced programmer in unity. Its based on this answer code http://answers.unity3d.com/questions/14361/open-and-close-a-door-with-a-keypress.html

All i want to do is when the player collides with the trigger, it start the animation on the Slider.

 using UnityEngine;
 using System.Collections;
     
 public class Door : MonoBehaviour {
     bool doorIsOpen = false;
     GameObject currentDoor;
     
 void DoDoor(bool openCheck, string SlideUp, GameObject thisDoor);
 
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
     
         //If the trigger collides with our Player
     if (collider.gameObject.name == "Player") {
             
             //Creating a RaycastHit Variable called hit
             RaycastHit hit; 
             
             //Throws the raycast 10 Unity Metres forward
             if(Physics.Raycast (transform.position, transform.forward, hit, 10)){
                 
                 //if the raycast collides with a gameobject called Slider1 and if the trigger is not trigged
                 if(hit.collider.gameObject.tag == "SliderUp" && doorIsOpen == false){
                     
                     //store the gameobject of the collider hit
                     currentDoor = hit.collider.gameObject;
                     
                     //call the Door() function with parameters for:
                     //DoorIsOpen, animation, currentDoor Gameobject
                     Door(true, "SlideUp", currentDoor);
                 }
                 }    
         }
         
 }
 
 
     //Start the slider function    
     void DoDoor(bool openCheck, string SlideUp, GameObject thisDoor){
             
             //Sets the DoorIsOpen variable to true or false
             doorIsOpen = openCheck;
             
             //Plays the animation clip SlipUp
             thisDoor.animation.Play("SlideUp");
 }
 
Comment
Add comment · Show 2
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
avatar image Graham-Dunnett ♦♦ · Nov 07, 2013 at 11:56 AM 0
Share

You haven't told us what goes wrong...

avatar image Graham-Dunnett ♦♦ · Nov 07, 2013 at 11:57 AM 0
Share

But I guess line 34 is meant to call DoDoor.

0 Replies

· Add your reply
  • Sort: 

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

16 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

Related Questions

How to Play an animation state on an animator controller on collision? 1 Answer

How to make my animated axe collide with tree properly?? 0 Answers

Animation with frozen player ?? 0 Answers

Possible to stop collider from "popping" through plane when re-centering? 2 Answers

Trying to play other objects' sound and animations from Raycast hit 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