Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 fluxhackspro · May 06, 2018 at 05:30 PM · animatoranimator controllerlayer

Animations and animator layers.

So i've done this soooo many times yet it dont work. I've changed the code and tried in so many different ways for about 5 hours now. And it's kinda awkward because this is just so easy normally and such a small part of my script. But heres the problem:

I have one animator layer with a running and a idle animation with a bool which is run. Simple. Then i have an other layer with a higher priority with animations like casting a spell and other actions, because i need to be able to cast a spell when running.

Im trying to instantiate an object 0.8 seconds after i start the animation because it fints right in there. And i need to have a cooldown which is easy too. But somehow it still dont work. And because i have it on GetKey i need to set the animation to false after i dont cast a spell. But if i just hold down "N" to cast a spell the animation is not synced at all with the actual casting of the spell and the animations are super glitched. Im pretty sure it has something to do with the animator layers. Any help is welcome!

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class PlayerController : MonoBehaviour {
 
     public float fireRate;
     public float force;
     public GameObject[] Particles;
 
     Animator anim;
     float nextFire;
 
     void Start ()
     {
         anim = GetComponent<Animator> ();
     }
 
     void Update ()
     {
         if (Input.GetKey (KeyCode.N) && Time.time > nextFire) {
             nextFire = Time.time + fireRate;
             anim.SetInteger ("Index", 1);
 
             GameObject magic = Instantiate (Particles [0]) as GameObject;
             magic.transform.position = transform.position + new Vector3 (0, 1.5f, 0);
             magic.transform.eulerAngles = transform.eulerAngles + new Vector3 (0, 180, 0);
             magic.GetComponent<Rigidbody> ().velocity = transform.forward * force * Time.deltaTime;
         }
         else if (!Input.GetKey (KeyCode.N))
         {
             anim.SetInteger ("Index", 0);
             Debug.Log ("NOT HOLDING DOWN ATTACK");
         }
     }
 }
 

Comment
Add comment · Show 1
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 TanselAltinel · May 07, 2018 at 01:13 PM 0
Share

Why don't you use Animation Events ins$$anonymous$$d of manually trying to find the timestamp in the animation?

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by fluxhackspro · May 07, 2018 at 04:00 PM

Thank you @TanselAltinel for the correct answer! I used an animation event on my actual animation and set up a custom function to controll the animation and movement glitches!

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

93 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Animation playing backwards in a layer 0 Answers

UFPS - Player Animation Setup 0 Answers

How to control an animation with both GetButton and GetButtonDown 0 Answers

Load Animator From XML without using UnityEditor 0 Answers

How to rotate an object with a script after an animation has rotated it? 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