void Update (){target = GameObject.Find("new_offer");// 滾輪設(shè)置 相機與人物的距離.if(Input.GetAxis("Mouse ScrollWheel") != 0){theDistance = theDistance + Input.GetAxis("Mouse ScrollWheel") * Time.deltaTime * ScrollKeySpeed;}// 鼠標(biāo)中間滾動得到的值是不確定的,不會正好就是0,或 -10,當(dāng)大于0時就設(shè)距離為0,小于MaxDistance就設(shè)置為MaxDistanceif(theDistance>0){ theDistance = 0;}if(theDistance < MaxDistance){ theDistance = MaxDistance;}transform.position = target.transform.position;SetDistance();}void Start (){if (rigidbody){rigidbody.freezeRotation = true;transform.position = target.transform.position;}}//設(shè)置相機與人物之間的距離void SetDistance(){transform.Translate(Vector3.forward * theDistance);}請問,運行時發(fā)現(xiàn)攝像頭只是上下移動,并不實現(xiàn)拉近后退的效果,這是為什么?
unity3d鼠標(biāo)滾輪實現(xiàn)攝像頭拉近后退
幕布斯7119047
2019-02-12 13:08:00