|
功能是:2个模型,选择第一个模型,选择的模型跟随鼠标移动,另一个模型不动。选择第二个模型,选择的模型跟随鼠标移动,第一个模型不动
问题是:选择一个模型,2个模型同时移动。
请哪位友人,帮我看一下,万分感谢了,我都内牛满面了!
PS:如果哪位朋友想要实现模型鼠标跟随移动的话,可以看看MouseMove脚本,做个参考,这个脚本实现的不错,但是没有做动画!
请大家帮帮忙,多提意见!不胜感激!
Select.js
- function Update ()
- {
- if (Input.GetMouseButton (0))
- {
- var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
- var hit : RaycastHit;
- if (Physics.Raycast(ray, hit))
- {
- Debug.DrawLine (ray.origin, hit.point);
- if(hit.collider.gameObject.name=="m1")
- {
- var foo:MouseMove1=GetComponent(MouseMove);
- foo.Update();
- }
- if(hit.collider.gameObject.name=="TankCube")
- {
- var foo1:MouseMove1=GetComponent(MouseMove);
- foo1.Update();
- }
- }
- }
- }
MouseMove.js
- var hit:RaycastHit;
- function Update()
- {
- if(Input.GetButtonDown("Fire1"))
- {
- var ray:Ray=Camera.main.ScreenPointToRay(Input.mousePosition);
- if(Physics.Raycast(ray,hit))
- {
- Debug.DrawLine(ray.origin,hit.point);
- print(hit.collider.gameObject.name);
- //animation.CrossFade("walk");
- }
- }
- if(hit.point!=Vector3(0,0,0)&&Vector3.Distance(hit.point,Vector3(transform.position.x,0,transform.position.z))>1.0)
- {
- turn(Vector3(hit.point.x,transform.position.y,hit.point.z));
- move();
- }
- else
- {
- //animation.CrossFade("idle");
- }
- print(Vector3.Distance(hit.point,transform.position));
- }
- function turn(look:Vector3)
- {
- var targetRotation=Quaternion.LookRotation(look-transform.position,Vector3.up);
- transform.rotation=Quaternion.Slerp(transform.rotation,targetRotation,Time.deltaTime*5.0);
- }
- function move()
- {
- transform.Translate(Vector3.forward*Time.deltaTime*3.8);
- }
|
|