キャラクターをAR鑑賞する
手動回転
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ManualRotate : MonoBehaviour
{
void Update()
{
transform.Rotate(new Vector3(0, Input.GetAxis("Mouse X") * 5, 0));
}
}
切り替えボタン1
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RotateSwitch : MonoBehaviour
{
public GameObject rabbit;
private bool isAutoRotateButtonOn = false;
public void OnRotateButtonClicked()
{
if (isAutoRotateButtonOn == false)
{
rabbit.GetComponent<AutoRotate>().enabled = true;
rabbit.GetComponent<ManualRotate>().enabled = false;
isAutoRotateButtonOn = true;
}
else if (isAutoRotateButtonOn == true)
{
rabbit.GetComponent<AutoRotate>().enabled = false;
rabbit.GetComponent<ManualRotate>().enabled = true;
isAutoRotateButtonOn = false;
}
}
}
切り替えボタン2
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// ★追加
using UnityEngine.UI;
public class RotateSwitch : MonoBehaviour
{
public GameObject rabbit;
private bool isAutoRotateButtonOn = false;
// ★追加
public GameObject button;
public void OnRotateButtonClicked()
{
if (isAutoRotateButtonOn == false)
{
rabbit.GetComponent<AutoRotate>().enabled = true;
rabbit.GetComponent<ManualRotate>().enabled = false;
isAutoRotateButtonOn = true;
// ★追加
button.GetComponent<Image>().color = Color.red;
}
else if (isAutoRotateButtonOn == true)
{
rabbit.GetComponent<AutoRotate>().enabled = false;
rabbit.GetComponent<ManualRotate>().enabled = true;
isAutoRotateButtonOn = false;
// ★追加
button.GetComponent<Image>().color = Color.white;
}
}
}
【2018版】AR_Project(全9回)
1 | AR版ピタゴラスイッチを作る |
2 | キャラクターをAR鑑賞する |
3 | ARシューティングゲームの開発 |
4 | キャラを破壊する |
5 | オリジナルのカーソルを作成する |
6 | カウンターを作成する |
7 | ★チャレンジ課題 |
手動回転
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ManualRotate : MonoBehaviour
{
void Update()
{
transform.Rotate(new Vector3(0, Input.GetAxis("Mouse X") * 5, 0));
}
}
切り替えボタン1
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RotateSwitch : MonoBehaviour
{
public GameObject rabbit;
private bool isAutoRotateButtonOn = false;
public void OnRotateButtonClicked()
{
if (isAutoRotateButtonOn == false)
{
rabbit.GetComponent<AutoRotate>().enabled = true;
rabbit.GetComponent<ManualRotate>().enabled = false;
isAutoRotateButtonOn = true;
}
else if (isAutoRotateButtonOn == true)
{
rabbit.GetComponent<AutoRotate>().enabled = false;
rabbit.GetComponent<ManualRotate>().enabled = true;
isAutoRotateButtonOn = false;
}
}
}
切り替えボタン2
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// ★追加
using UnityEngine.UI;
public class RotateSwitch : MonoBehaviour
{
public GameObject rabbit;
private bool isAutoRotateButtonOn = false;
// ★追加
public GameObject button;
public void OnRotateButtonClicked()
{
if (isAutoRotateButtonOn == false)
{
rabbit.GetComponent<AutoRotate>().enabled = true;
rabbit.GetComponent<ManualRotate>().enabled = false;
isAutoRotateButtonOn = true;
// ★追加
button.GetComponent<Image>().color = Color.red;
}
else if (isAutoRotateButtonOn == true)
{
rabbit.GetComponent<AutoRotate>().enabled = false;
rabbit.GetComponent<ManualRotate>().enabled = true;
isAutoRotateButtonOn = false;
// ★追加
button.GetComponent<Image>().color = Color.white;
}
}
}
キャラクターをAR鑑賞する