unity

#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;
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值