- Home /
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.
Your answer
Follow this Question
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