Clamp를 사용하면 원하는 값을 딱 얻을 수 있네
설명
Clamps a value between a minimum float and maximum float value.
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour {
void Update() {
transform.position = new Vector3(Mathf.Clamp(Time.time, 1.0F, 3.0F), 0, 0);
}
}
public static int Clamp (int value, int min, int max);
설명
Clamps value between min and max and returns value.
// Clamps the value 10 to be between 1 and 3.
// prints 3 to the console
Debug.Log(Mathf.Clamp(10, 1, 3));
무한루프
public void Next_Color()
{
if (currnetIndex + 1 == color_materials.Length)
currnetIndex = 0;
else
currnetIndex = Mathf.Clamp(currnetIndex + 1, 0, color_materials.Length- 1);
SetObjectColor(color_materials[currnetIndex]);
}
public void Prev_Color()
{
if (currnetIndex-1 == -1)
currnetIndex = color_materials.Length - 1;
else
currnetIndex = Mathf.Clamp(currnetIndex - 1, 0, color_materials.Length - 1);
SetObjectColor(color_materials[currnetIndex]);
}
예제
public void Prev_Help()
{
currnetIdx = Mathf.Clamp(currnetIdx - 1, 0, helpDatas.helperInfos.Count-1);
tts.Instance.SpeechStop();
HelperInfo result = helpDatas.helperInfos[currnetIdx];
StartDroneMove(result.move, result.rotate);
tts.Instance.Speech(result.txt_tts);
}
public void Next_Help()
{
currnetIdx = Mathf.Clamp(currnetIdx + 1, 0, helpDatas.helperInfos.Count-1);
tts.Instance.SpeechStop();
HelperInfo result = helpDatas.helperInfos[currnetIdx];
StartDroneMove(result.move,result.rotate);
tts.Instance.Speech(result.txt_tts);
}
댓글 없음:
댓글 쓰기