Home > other >  Seek unity big operation code, good could not
Seek unity big operation code, good could not

Time:09-16

Made by the mouse to click after a ray, ray run into cubes, cube rotation, ray touched the ball constantly move, then have a recovery key, click the back button to restore the original position after the ball and cube, below is my pick to along while, gather together the code, is wrong, please help, thank you

CodePudding user response:

This code can't see you ah

CodePudding user response:

1/f, residual reference both failed Pi response:
you couldn't see the code

Code I already success for him to recover, but I want to let the ball movement, not a ray hit move, but always, thank you

Ublic class c00: MonoBehaviour {//Use this for initialization
Public float speed;
Private Camera _camera;
Private GameObject ob.
Private bool MovementPosition;
Private Vector3 spherePosition;
Void the Start () {
_camera=GetComponent (a);
}//Update is called once per frame void the Update () {
{if (Input. GetMouseButton (0))
Ray rays=_camera. ScreenPointToRay (Input. MousePosition);//a ray Debug. DrawRay (rays. Origin, rays direction * 100, Color. Blue);//a blue line RaycastHit hit;//create a RaycastHit feedback variable used to store the if (Physics. Raycast (rays, out hit)) {if (hit) starts) name=="sphere") {ob=hit. Starts. GameObject; Ob. GetComponent (). MovePosition (ob) transform) + Vector3 position. The speed right * * Time. The deltaTime); }}

CodePudding user response:

refer to the second floor weixin_45277641 response:
Quote: refer to 1st floor crashing residual sunset Pi response:
you couldn't see the code

Code I already success for him to recover, but I want to let the ball movement, not a ray hit move, but always, thank you

Ublic class c00: MonoBehaviour {//Use this for initialization
Public float speed;
Private Camera _camera;
Private GameObject ob.
Private bool MovementPosition;
Private Vector3 spherePosition;
Void the Start () {
_camera=GetComponent (a);
}//Update is called once per frame void the Update () {
{if (Input. GetMouseButton (0))
Ray rays=_camera. ScreenPointToRay (Input. MousePosition);//a ray Debug. DrawRay (rays. Origin, rays direction * 100, Color. Blue);//a blue line RaycastHit hit;//create a RaycastHit feedback variable used to store the if (Physics. Raycast (rays, out hit)) {if (hit) starts) name=="sphere") {ob=hit. Starts. GameObject; Ob. GetComponent (). MovePosition (ob) transform) + Vector3 position. The speed right * * Time. The deltaTime); }}



Learn to look at the API, you use MovePosition, this method is to move to a certain position, do you want to use ob motion. GetComponent (). Velocity=transform. Forward * Time. DeltaTime * 100; Here I am object before direction, moving direction and speed yourself
  • Related