Open Project, select Assets > import package > Custom Package and import NRSDKForUnityAndroid_1.7.0.unitypackage.
2. Put a Canvas in the scene
Put Canvas from Create > UI
Set property on Inspector panel
Render Mode : World Space
Pos X : 0 , Pos Y : -0.35 Pos Z : 3
Scale
X : 0.005 , Y : 0.005 , Z : 0.005
3. Put Text in Canvas
Put Text as a child of Canvas
Pos X : 0, Pos Y : -30, Pos Z : 3
Change Text to “Rotate Cube” on Inspector panel.
Change Color to “FFFFFF” on Inspector panel.
4. Create C# Script in Assets
Create C# Script in the asset with the file name "RotateButton.cs".
Write the code as follows
usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;usingUnityEngine.EventSystems;publicclassRotateButton:MonoBehaviour,IPointerUpHandler,IPointerDownHandler{/// <summary>/// Target Object/// </summary>publicGameObjectTargetCube;/// <summary>/// Rotation Type/// </summary>publicRotationTypeEnumRotationType;/// <summary>/// Number of rotations at a time/// </summary>privatestaticreadonlyintROTATE=1;/// <summary>/// Press flag/// </summary>privateboolisPressed=false;/// <summary>/// Rotation Type Enum/// </summary>publicenumRotationTypeEnum{LEFT,RIGHT}// Start is called before the first frame updatevoidStart(){}// Update is called once per framevoidUpdate(){if(isPressed){if(RotationType==RotationTypeEnum.RIGHT){TargetCube.transform.Rotate(newVector3(0,ROTATE,0));}elseif(RotationType==RotationTypeEnum.LEFT){TargetCube.transform.Rotate(newVector3(0,-ROTATE,0));}}}/// <summary>/// Pointer up event handler/// </summary>/// <param name="eventData"></param>publicvoidOnPointerUp(PointerEventDataeventData){isPressed=false;}/// <summary>/// Pointer down event handler/// </summary>/// <param name="eventData"></param>publicvoidOnPointerDown(PointerEventDataeventData){isPressed=true;}}
5. Put Cube in the Scene
Put Cube in the Scene
Change name to “RotatableCube”
Pos X : 0, Pos Y : 0, Pos Z : 8
6. Put “Rotate Right” Button in Canvas
Put Button as a child of Canvas
Pos X : 60, Pos Y : 0, Pos Z : 0
Width : 100
Change Text to “Rotate Right” from nested Text.
Attach the RotateButton.cs on Inspector panel.
Set Target Cube to RotatableCube you just created.
Set Rotation Type to RIGHT.
7. Put “Rotate Left” Button in Canvas
Put Button as a child of Canvas
Pos X : -60, Pos Y : 0, Pos Z : 0
Width : 100
Change Text to “Rotate Left” from nested Text.
Attach the RotateButton.cs on Inspector panel.
Set Target Cube to RotatableCube you just created.
Set Rotation Type to LEFT.
8. Build
Press Build form Build Settings panel
Install *.apk on Android or DevKit.
Top comments (0)
Subscribe
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)