2022년 9월 21일 수요일

unity array get next prev index

 


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);

       
       
    }

댓글 없음:

댓글 쓰기

git rejected error(feat. cherry-pick)

 문제 아무 생각 없이 pull을 받지않고 로컬에서 작업! 커밋, 푸시 진행을 해버렷다. push에선 remote와 다르니 당연히 pull을 진행해라고 하지만 로컬에서 작업한 내용을 백업하지 않고 진행하기에는 부담스럽다(로컬작업 유실 가능성) 해결하려...