# 【Unity3d工作日志】知识点20180517

1.

初始值：
mCamTrans = Camera.main.transform;
Vector3 startPos = transform.position;
startPos.y += mCamHeight;
mCamTrans.position = startPos;
mCamTrans.rotation = transform.rotation;
mCamAng = mCamTrans.eulerAngles;

If(Input.GetKey(KeyCode.W/S/A/D)
{
mPlayer.transform.Translate(Vector3.forward/back/left/right * Time.deltaTime *      mSpeed);
}

float y = Input.GetAxis("Mouse X");
float x = Input.GetAxis("Mouse Y");
mCamAng.x -= x;
mCamAng.y += y;
mCamTrans.eulerAngles = mCamAng;
mCamTrans.position = new Vector3(this.transform.position.x, mCamTrans.position.y,   this.transform.position.z);

float camy = mCamAng.y;
this.transform.eulerAngles = new Vector3(this.transform.eulerAngles.x, camy,    this.transform.eulerAngles.z);
Vector3 startPos = transform.position;
startPos.y += mCamHeight;
mCamTrans.position = startPos;

2.

普通状态图：

Sprite _si = Resources.Load(“Textures/selectedImg”,typeof(Sprite)) as Sprite;
SpriteState _ss = new SpriteState();
_ss.highlightedSprite = _si;
_ss.pressedSprite = null;
_ss.disabledSprite = null;
mBtn.Getcomponent<Button>().spriteState = _ss;

3.

mObj.transform.position = Camera.main.ScreenToWorldPoint(Input.mousePosition + new Vector3((float)offsetX,offsetY,offsetZ);

ps:当offsetX/Y/Z = 0时，通过预制件实例化出来的3d模型position与主摄像机position一致，且不跟随鼠标移动，所以需要设置偏移量

4.

Vector3 _objScreenPos = Camera.main.WorldToScreenPoint(_obj.transform.position);
mUI.Getcomponent<RectTransform>().position = new Vector3(_objScreenPos.x,_objScreenPos.y,0);