#pragma strict
var frameNumber:int=3;
var destory:boolean=false;
private var index:int=0;
private var frameRate:float=0;
private var myTime:float=0;
private var myIndex:int=0;
function Start () {
frameRate=0.1f/frameNumber;
}
function Update () {
myTime+=Time.deltaTime;
myIndex=myTime*frameNumber;
index =myIndex%frameNumber;
if(index==frameNumber-1)
destory(GameObject);
}
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(Animator))]
public class playnong : MonoBehaviour {
private Animator playerAnimator = null;
private PlayStateContorller.playStates currentState=PlayStateContorller.playStates.up;
public void Start(){
playerAnimator = GetComponent<Animator> ();
}
/*void LateUpdate()
{
onStateCycle();
}*/
if(Input.GetMouseButtonDown(0))
{
playerAnimator.SetBool("Down",false);
}
else
{
playerAnimator.SetBool("Down",true);
}
}
using UnityEngine;
using System.Collections;
public class PlayerStateController : MonoBehaviour {
// Use this for initialization
public enum playerStates
{
idle=0,
left,
right,
}
public delegate void playerStateHandler(PlayerStateController.playerStates newState);
public static event playerStateHandler onStateChange;
void LateUpdate()
{
float horizontal = Input.GetAxis ("Horizontal");
if (horizontal != 0.0f) {
if (horizontal < 0.0f) {
if (onStateChange != null)
onStateChange (PlayerStateController.playerStates.left);
} else {
if (onStateChange != null)
onStateChange (PlayerStateController.playerStates.right);
}
} else {
if (onStateChange != null)
onStateChange (PlayerStateController.playerStates.idle);
}
}
}
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(Animator))]
public class PlayerStateListener : MonoBehaviour {
public float playerWalkSpeed = 3f;
private Animator playerAnimator = null;
private PlayerStateController.playerStates currentState = PlayerStateController.playerStates.idle;
void OnEnable()
{
PlayerStateController.onStateChange += onStateChange;
}
void onEndable()
{
PlayerStateController.onStateChange -= onStateChange;
}
void Start()
{
playerAnimator = GetComponent<Animator> ();
}
void LataUpdate()
{
onStateCycle ();
}
void onStateCycle ()
{
Vector3 localScale=transform.localScale;
switch (currentState)
{
case PlayerStateController.playerStates.idle:
break;
case PlayerStateController.playerStates.left:
transform.Translate(
new Vector3((playerWalkSpeed*-1.0f)*Time.deltaTime,0.0f,0.0f));
if (localScale.x>0.0f)
{
localScale.x*=-1.0f;
transform.localScale=localScale;
}
break;
}
}
public void onStateChange(PlayerStateController.playerStates newState)
{
if (newState == currentState)
return;
if (!checkForValidStatePair (newState))
return;
switch(newState)
{
case PlayerStateController.playerStates.idle:
playerAnimator.SetBool("Down",false);
break;
case PlayerStateController.playerStates.left:
playerAnimator.SetBool("Down",true);
break;
case PlayerStateController.playerStates.right:
playerAnimator.SetBool("Down",true);
break;
}
currentState = newState;
}
bool checkForVaildStatePair(PlayerStateController.playerStates newState)
{
bool returnVal = false;
switch (currentState)
{
case PlayerStateController.playerStates.idle:
returnVal=true;
break;
case PlayerStateController.playerStates.left:
returnVal=true;
break;
case PlayerStateController.playerStates.right:
returnVal=true;
break;
}
return returnVal;
}
}
var frameNumber:int=3;
var destory:boolean=false;
private var index:int=0;
private var frameRate:float=0;
private var myTime:float=0;
private var myIndex:int=0;
function Start () {
frameRate=0.1f/frameNumber;
}
function Update () {
myTime+=Time.deltaTime;
myIndex=myTime*frameNumber;
index =myIndex%frameNumber;
if(index==frameNumber-1)
destory(GameObject);
}
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(Animator))]
public class playnong : MonoBehaviour {
private Animator playerAnimator = null;
private PlayStateContorller.playStates currentState=PlayStateContorller.playStates.up;
public void Start(){
playerAnimator = GetComponent<Animator> ();
}
/*void LateUpdate()
{
onStateCycle();
}*/
if(Input.GetMouseButtonDown(0))
{
playerAnimator.SetBool("Down",false);
}
else
{
playerAnimator.SetBool("Down",true);
}
}
using UnityEngine;
using System.Collections;
public class PlayerStateController : MonoBehaviour {
// Use this for initialization
public enum playerStates
{
idle=0,
left,
right,
}
public delegate void playerStateHandler(PlayerStateController.playerStates newState);
public static event playerStateHandler onStateChange;
void LateUpdate()
{
float horizontal = Input.GetAxis ("Horizontal");
if (horizontal != 0.0f) {
if (horizontal < 0.0f) {
if (onStateChange != null)
onStateChange (PlayerStateController.playerStates.left);
} else {
if (onStateChange != null)
onStateChange (PlayerStateController.playerStates.right);
}
} else {
if (onStateChange != null)
onStateChange (PlayerStateController.playerStates.idle);
}
}
}
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(Animator))]
public class PlayerStateListener : MonoBehaviour {
public float playerWalkSpeed = 3f;
private Animator playerAnimator = null;
private PlayerStateController.playerStates currentState = PlayerStateController.playerStates.idle;
void OnEnable()
{
PlayerStateController.onStateChange += onStateChange;
}
void onEndable()
{
PlayerStateController.onStateChange -= onStateChange;
}
void Start()
{
playerAnimator = GetComponent<Animator> ();
}
void LataUpdate()
{
onStateCycle ();
}
void onStateCycle ()
{
Vector3 localScale=transform.localScale;
switch (currentState)
{
case PlayerStateController.playerStates.idle:
break;
case PlayerStateController.playerStates.left:
transform.Translate(
new Vector3((playerWalkSpeed*-1.0f)*Time.deltaTime,0.0f,0.0f));
if (localScale.x>0.0f)
{
localScale.x*=-1.0f;
transform.localScale=localScale;
}
break;
}
}
public void onStateChange(PlayerStateController.playerStates newState)
{
if (newState == currentState)
return;
if (!checkForValidStatePair (newState))
return;
switch(newState)
{
case PlayerStateController.playerStates.idle:
playerAnimator.SetBool("Down",false);
break;
case PlayerStateController.playerStates.left:
playerAnimator.SetBool("Down",true);
break;
case PlayerStateController.playerStates.right:
playerAnimator.SetBool("Down",true);
break;
}
currentState = newState;
}
bool checkForVaildStatePair(PlayerStateController.playerStates newState)
{
bool returnVal = false;
switch (currentState)
{
case PlayerStateController.playerStates.idle:
returnVal=true;
break;
case PlayerStateController.playerStates.left:
returnVal=true;
break;
case PlayerStateController.playerStates.right:
returnVal=true;
break;
}
return returnVal;
}
}