Hello!
My Game is a 2d Game.
I have a GameObject Player with the script characterManager that controls movement and Animations. The problem is that, I use different skins for the Player, 3 actually. Every Skin is a different sprite with different Animators but all the Animators Triggers are called in the same way.
using UnityEngine;
using System.Collections;
public class CharacterManager : MonoBehaviour {
Vector3 velocity = Vector3.zero;
public Vector3 gravity;
public Vector3 flapVelocity;
public float maxSpeed = 5f;
public bool shieldPowerUp = false;
static CharacterManager myInstance;
// int score = 0;
//string scoreText = "Score: 0";
bool didFlap = false;
float deathCooldown;
Animator animator;
public bool dead = false;
public bool gameOver = false;
public bool godMode = false;
public static CharacterManager Instance
{
get
{
if (myInstance == null)
myInstance = FindObjectOfType(typeof(CharacterManager)) as CharacterManager;
return myInstance;
}
}
// Use this for initialization
void Start () {
}
// Do Graphics & Input updates here
void Update (){
if (!animator) {
animator = transform.GetComponentInChildren<Animator> ();
}
if (dead==false) {
if (Input.GetKeyDown (KeyCode.Space) || Input.GetMouseButtonDown (0)) {
didFlap = true;
}
}
if(dead) {
deathCooldown -= Time.deltaTime;
if (deathCooldown <= 0) {
Time.timeScale = 0;
gameOver = true;
GameObject.Find("menu_button_pause").GetComponent<PauseControl>().paused = true;
}
}
if (shieldPowerUp == true) {
godMode = true;
}
}
// Do physics engine updates here
void FixedUpdate () {
if (dead)
return;
velocity += gravity * Time.deltaTime;
if (didFlap == true) {
animator.SetTrigger ("DoFlap");
didFlap = false;
if (velocity.y < 0)
velocity.y = 0;
velocity += flapVelocity;
}
velocity = Vector3.ClampMagnitude (velocity, maxSpeed);
transform.position += velocity * Time.deltaTime;
}
void OnCollisionEnter2D(Collision2D gameObject) {
if(godMode)
return;
animator.SetTrigger("Death");
dead = true;
deathCooldown = 0.8f;
}
}
When I use the classic skin, everything is good. But when I change to another skin, the Animator animator doesn’t initalize and the Other Skins Animations are’nt played and I think is because it just Initialized with the classic Skin and it can’t do it again.
How do I make that my Animator Initialize with every Skin.
P.D. All the Skins are children of the Player GameObject
P.D. When I Change Skin, the old skin’s gameobject is disabled and the new one is enabled.
Thanks!