This content originally appeared on DEV Community and was authored by Kazuhiro Hara™
Sample Repository
Run the sample
- Download NRSDK 1.7.0 from https://nreal-public.nreal.ai/download/NRSDKForUnityAndroid_1.7.0.unitypackage
- Open
Build Setting, change Platform toAndroid - Open
Project, selectAssets>import package>Custom Packageand importNRSDKForUnityAndroid_1.7.0.unitypackage. - Check
Build Settings>Player Settingsby referring to Configure Build Settings - Press
BuildformBuild Settingspanel - Install *.apk on Android or DevKit.
Tutorial
1. Setting up the project for Nreal development
- See Quickstart for Android - NRSDK Documentation and configure the build settings.
- Download NRSDK 1.7.0 from https://nreal-public.nreal.ai/download/NRSDKForUnityAndroid_1.7.0.unitypackage
- Open
Project, selectAssets>import package>Custom Packageand importNRSDKForUnityAndroid_1.7.0.unitypackage.
2. Put a Canvas in the scene
- Put
CanvasfromCreate>UI - Set property on
Inspectorpanel-
Render Mode: World Space -
Pos X: 0 ,Pos Y: -0.35Pos Z: 3 -
Scale-
X: 0.005 ,Y: 0.005 ,Z: 0.005
-
-
3. Put Text in Canvas
- Put
Textas a child ofCanvas-
Pos X: 0,Pos Y: -30,Pos Z: 3
-
- Change Text to “Rotate Cube” on
Inspectorpanel. - Change Color to “FFFFFF” on
Inspectorpanel.
4. Create C# Script in Assets
- Create
C# Scriptin the asset with the file name "RotateButton.cs". - Write the code as follows
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class RotateButton : MonoBehaviour, IPointerUpHandler, IPointerDownHandler
{
/// <summary>
/// Target Object
/// </summary>
public GameObject TargetCube;
/// <summary>
/// Rotation Type
/// </summary>
public RotationTypeEnum RotationType;
/// <summary>
/// Number of rotations at a time
/// </summary>
private static readonly int ROTATE = 1;
/// <summary>
/// Press flag
/// </summary>
private bool isPressed = false;
/// <summary>
/// Rotation Type Enum
/// </summary>
public enum RotationTypeEnum
{
LEFT,
RIGHT
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (isPressed)
{
if (RotationType == RotationTypeEnum.RIGHT)
{
TargetCube.transform.Rotate(new Vector3(0, ROTATE, 0));
}
else if (RotationType == RotationTypeEnum.LEFT)
{
TargetCube.transform.Rotate(new Vector3(0, -ROTATE, 0));
}
}
}
/// <summary>
/// Pointer up event handler
/// </summary>
/// <param name="eventData"></param>
public void OnPointerUp(PointerEventData eventData)
{
isPressed = false;
}
/// <summary>
/// Pointer down event handler
/// </summary>
/// <param name="eventData"></param>
public void OnPointerDown(PointerEventData eventData)
{
isPressed = true;
}
}
5. Put Cube in the Scene
- Put
Cubein the Scene- Change name to “RotatableCube”
-
Pos X: 0,Pos Y: 0,Pos Z: 8
6. Put “Rotate Right” Button in Canvas
- Put
Buttonas a child ofCanvas-
Pos X: 60,Pos Y: 0,Pos Z: 0 -
Width: 100
-
- Change Text to “Rotate Right” from nested
Text. - Attach the
RotateButton.csonInspectorpanel.- Set
Target Cubeto RotatableCube you just created. - Set
Rotation Typeto RIGHT.
- Set
7. Put “Rotate Left” Button in Canvas
- Put
Buttonas a child ofCanvas-
Pos X: -60,Pos Y: 0,Pos Z: 0 -
Width: 100
-
- Change Text to “Rotate Left” from nested
Text. - Attach the
RotateButton.csonInspectorpanel.- Set
Target Cubeto RotatableCube you just created. - Set
Rotation Typeto LEFT.
- Set
This content originally appeared on DEV Community and was authored by Kazuhiro Hara™
Print
Share
Comment
Cite
Upload
Translate
Updates
There are no updates yet.
Click the Upload button above to add an update.
APA
MLA
Kazuhiro Hara™ | Sciencx (2022-02-09T23:35:01+00:00) Cube Rotation – MR Tutorial for Nreal light. Retrieved from https://www.scien.cx/2022/02/09/cube-rotation-mr-tutorial-for-nreal-light/
" » Cube Rotation – MR Tutorial for Nreal light." Kazuhiro Hara™ | Sciencx - Wednesday February 9, 2022, https://www.scien.cx/2022/02/09/cube-rotation-mr-tutorial-for-nreal-light/
HARVARDKazuhiro Hara™ | Sciencx Wednesday February 9, 2022 » Cube Rotation – MR Tutorial for Nreal light., viewed ,<https://www.scien.cx/2022/02/09/cube-rotation-mr-tutorial-for-nreal-light/>
VANCOUVERKazuhiro Hara™ | Sciencx - » Cube Rotation – MR Tutorial for Nreal light. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/02/09/cube-rotation-mr-tutorial-for-nreal-light/
CHICAGO" » Cube Rotation – MR Tutorial for Nreal light." Kazuhiro Hara™ | Sciencx - Accessed . https://www.scien.cx/2022/02/09/cube-rotation-mr-tutorial-for-nreal-light/
IEEE" » Cube Rotation – MR Tutorial for Nreal light." Kazuhiro Hara™ | Sciencx [Online]. Available: https://www.scien.cx/2022/02/09/cube-rotation-mr-tutorial-for-nreal-light/. [Accessed: ]
rf:citation » Cube Rotation – MR Tutorial for Nreal light | Kazuhiro Hara™ | Sciencx | https://www.scien.cx/2022/02/09/cube-rotation-mr-tutorial-for-nreal-light/ |
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.
