Home > other >  How do you write ask implement the following c # script
How do you write ask implement the following c # script

Time:09-26


Using radiographic testing, implementation: three Cube, click on one of them, if the Cube is motionless, then the Cube will rotate, other stop rotating Cube; If the Cube is rotating, the square stop rotating, the other square,

CodePudding user response:


Public GameObject [] _Cubes;
Public int _Speed=30;
Bool isRotation1=false;
Bool isRotation2=false;
Bool isRotation3=false;

Private void the Update ()
{
If (Input. GetMouseButtonDown (0))
{
Ray Ray=Camera. Main. ScreenPointToRay (Input. MousePosition);
RaycastHit hit;
Bool isHit=Physics. Raycast (ray, out hit).
If (isHit)
{
If (hit) the transform) name=="Cube1")
{
The Debug Log (" click cube 1 ");
If (isRotation1) isRotation1=false;
The else isRotation1=true;
IsRotation2=false;
IsRotation3=false;
}
Else if (hit) the transform) name=="Cube2")
{
The Debug Log (" click cube 2 ");
If (isRotation2) isRotation2=false;
The else isRotation2=true;
IsRotation1=false;
IsRotation3=false;
}
Else if (hit) the transform) name=="Cube3)
{
The Debug Log (" click cube 3 ");
If (isRotation3) isRotation3=false;
The else isRotation3=true;
IsRotation2=false;
IsRotation1=false;
}
}
}

If (isRotation1) _Cubes [0]. The transform, Rotate (Vector3. _Speed forward * * Time. DeltaTime);
If (isRotation2) _Cubes [1]. The transform, Rotate (Vector3. _Speed forward * * Time. DeltaTime);
If (isRotation3) _Cubes [2]. The transform, Rotate (Vector3. _Speed forward * * Time. DeltaTime);

}

CodePudding user response:

You are written out, where is wrong?
  • Related