I have this 2D animated sprite I am trying to get to move from another script but for some reason only the animation will play but the sprite does not move?
//UP Movement Direction Control
public void COne_DirectionUP(){
Fig01Ani = FigureOne.GetComponent<Animator>();
IconFigOne = GameObject.Find("Figure01Ani").GetComponent<Rigidbody2D>();
IconFigOne.transform.Translate (Vector2.up * speed);
//SFXmanager SFXfw = FindObjectOfType<SFXmanager> ();
//SFXfw.FigWalkSFX ();
Fig01Ani.Play ("Fig01MoveAni");
}
Thanks @Fydar I figured it out as it turns out that blasted “transform.Translate” seemed to ONLY want to work inside of update so I had to get a little crafty with some bools to check if my desired direction was true or false and then call my direction moment inside of the update… not sure if there was a more appropriate way to do this but this seems to work.
using UnityEngine;
using System.Collections;
using System;
public class Character01Input : MonoBehaviour {
//Reference to the Character 01 Game Object
public GameObject FigureOne;
//animator reference
private Animator Fig01Ani;
public float speed;
public Rigidbody2D IconFigOne;
//Direction Bools
public bool dirUp = false; //UP
public bool dirDown = false; //Down
public bool dirLeft = false; //Left
public bool dirRight = false; //Right
public bool stopMove = false; //Stop
void Start(){
Fig01Ani = FigureOne.GetComponent<Animator>();
IconFigOne = GetComponent<Rigidbody2D> ();
//disable it on start to stop it from playing the default animation
Fig01Ani.enabled = false;
}
void Update () {
if (stopMove == true) {//Stop
Fig01Ani.enabled = true;
//SFXmanager SFXfw = FindObjectOfType<SFXmanager> ();
//SFXfw.FigWalkSFX ();
Fig01Ani.Play ("Fig01IdleAni");
}
if (dirRight == true) {//Start RIGHT Movement
Fig01Ani.enabled = true;
transform.Translate (Vector2.right * speed);
//SFXmanager SFXfw = FindObjectOfType<SFXmanager> ();
//SFXfw.FigWalkSFX ();
Fig01Ani.Play ("Fig01MoveAni");
}
if (dirLeft == true) {//Start LEFT Movement
Fig01Ani.enabled = true;
transform.Translate (-Vector2.right * speed);
//SFXmanager SFXfw = FindObjectOfType<SFXmanager> ();
//SFXfw.FigWalkSFX ();
Fig01Ani.Play ("Fig01MoveAni");
}
if (dirUp == true) {//start UP Movement
Fig01Ani.enabled = true;
transform.Translate (Vector2.up * speed);
//SFXmanager SFXfw = FindObjectOfType<SFXmanager> ();
//SFXfw.FigWalkSFX ();
Fig01Ani.Play ("Fig01MoveAni");
}
if (dirDown == true) {//Start DOWN Movement
Fig01Ani.enabled = true;
transform.Translate (-Vector2.up * speed);
//SFXmanager SFXfw = FindObjectOfType<SFXmanager> ();
//SFXfw.FigWalkSFX ();
Fig01Ani.Play ("Fig01MoveAni");
}
}
//UP Movement Direction Control
public void COne_DirectionUP(){
dirUp = true;
dirDown = false;
dirLeft = false;
dirRight = false;
stopMove = false;
}
}