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 FrosTech · Aug 19, 2014 at 04:16 AM · c#animationandroid

Anisprite animation from OnTriggerEnter

Hi there.

I am working on a spring that lifts the player up into the air. While that happens, the spring plays a 7 frame animation completely. Actually there are 4 frames but, the remaining 3 put it back to initial position.

This happens when the player triggers the trigger zone of "Spring GO", and plays the 7 frame animation, and lifts the player into the desire direction, currently ony above is set.

I have no problem with the lifting in the air, as it is handled by the CharacterController, but the spring animation seems to be running only when the player enters the trigger, after that it stops to play at random frames, not completing the 7 frame cycle.

And, that's a freakish problem bugging me.

 using UnityEngine;
 using System.Collections;
 
 public enum SpringColor {black=0,yellow=1,red=2,white=3}

 // Used for animation only
 public class SpringAnimator : MonoBehaviour
 {    
     AniSprite aniPlay;    
     public bool doAnimate = false;
     public int fps;    
     
     private float duration;
     
     // Use this for initialization
     void Start () 
     {
         aniPlay = GetComponent<AniSprite>();
     }
     
     void Update ()
     {
         
         
         if ( doAnimate )
         {
             Animate ( fps );
             
             
         }
         
         
     }
     
     
     // Update is called once per frame
     public void Animate(int fps) 
     {
         aniPlay.animate (8,4,0,3,7,fps);
         
         doAnimate = false;
     }    
 }

 using UnityEngine;
 using System.Collections;
 
 public class SpringJumpManager : MonoBehaviour {
     
     public float jumpForce;
     public SpringAnimator animator;
     
     
     void OnTriggerEnter(Collider other)
     {
         
        if (other.gameObject.tag == "Bounce")
         {            
             print ("Player found, now will jump!!");
             animator.doAnimate = true;
             other.gameObject.GetComponent<PlayerControls>().Bounce(Vector3.zero,jumpForce);            
         }
     }
 }



 using UnityEngine;
 using System.Collections;
 
 public class AniSprite : MonoBehaviour 
 {
    
 
     public void animate( int columnSize, int rowSize, int colFrameStart, int rowFrameStart, int totalFrames, int framesPerSecond)
     {
         int        index                         = (int)(Time.time * framesPerSecond);                                 // uses Time and the FPS value to set the animation frame to display
                 index                         = index % totalFrames;                                                // modulates the index so the animation loops
         
         Vector2 size = new Vector2 ( 1.0f / columnSize, 1.0f / rowSize);                                                        // scale for column and row size
         
         int        u                             = index % columnSize;
         int        v                             = index / columnSize;
         
         
         Vector2 offset                        = new Vector2 ((float)((u + colFrameStart) * size.x),(float)((1.0 - size.y) - (v + rowFrameStart) * size.y));        // stores the value to offset the object's texture
 
         renderer.material.mainTextureOffset = offset;                                                    // texture offset for diffuse map
         renderer.material.mainTextureScale  = size;                                                        // texture scale  for diffuse map
                                                                  
 
         renderer.material.SetTextureOffset ("_MainTex", offset);                                        // texture offset for bump (normal map)
         renderer.material.SetTextureScale  ("_MainTex", size);                                            // texture scale  for bump (normal map) 
     }
 
 
 }
 

SpringJumpManager doesn't play that much roll into animation, but it does state to play the animation through "doAnimate" property.

Any suggestions on this issue will be appreciated. Thanks.

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

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

21 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

Related Questions

AI Animation problems 1 Answer

Is there a function that will return the current frame of an animation? 1 Answer

Distribute terrain in zones 3 Answers

My high score do not update after restart 2 Answers

play only one door animation 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