Unity常用语法
原创
©著作权归作者所有:来自51CTO博客作者zswnet的原创作品,谢绝转载,否则将追究法律责任
输入:
if(Input.anyKeyDown)
if(Input.GetKeyDown(KeyCode.Keypad0))
if (Input.GetMouseButtonDown(0))
if (Input.GetAxis(
"Mouse X") > 0)
射线判断点击

Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

RaycastHit hit;

var layerMask = 1 << 8;
if (Physics.Raycast(ray,
out hit, 1000
/*,layerMask*/))

{

Debug.DrawLine(ray.origin, hit.point);
if (hit.transform.name ==
"add")
itween

iTween.ScaleFrom(hit.transform.gameObject, iTween.Hash(
"x", 60,
"y", 30,
"z", 10,
"time", 0.5f,
"delay", 0.1f));

Transform
transform.Rotate( CommonConstBattle.myWarriorDirection);
transform.Translate( new Vector3(-CommonConstBattle.enemySpeedRun * Time.deltaTime ,0,0),Space.World);
gameobject
public SphereCollider sc;

gameObject.AddComponent(
"FoobarScript");

sc = gameObject.AddComponent(
"SphereCollider")
as SphereCollider;
animator
private Animator animator;
private AnimatorStateInfo stateInfo;
animator = GetComponent<Animator> ();

animator.SetFloat(
"***",0.1f);
stateInfo = animator.GetCurrentAnimatorStateInfo (0);
if(stateInfo.IsName("Base Layer.idle")){}
静态单例
static UICursor mInstance;
void Awake () { mInstance =
this; }
void OnDestroy () { mInstance =
null; }
代理
//**********************发消息
public delegate void timebar_delegate();
public static event timebar_delegate time_bar_end_make_gold;

在代码中调用time_bar_end_make_gold()

提供cleanDelegate(){

time_bar_end_make_gold=
null;

}
//***********************接收
cleanDelegate()

timer_bar_control.time_bar_end_upgrade_iron+=upgrade_finish;
//收到消息后跳转到函数
upgrade_finish(){

........

}
