Yang.공부방

Mathf.Repeat(float t, float length);

: t를 0부터 length안의 범위로 반복시키는 메서드(t는 0보다 크고 length보다 작아야한다)

ex) Mathf.Repeat(3.0, 2.5) 의 결과 값 : 0.5

최소값 : 0, 최대값 : length

무조건 양수여야 하고 제한된 값만큼만 나오게 할 때 사용한다.




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class TestBGScroller : MonoBehaviour
{
    public Transform[] arrGround;
    public float speed = 5f;
    private float tileSize = 30;
    Vector3 movePosition;
 
    //수업중에 한것(단점 : new Vector3 하는 동안에도 이동중이므로 틈이 생긴다
    private void Update()
    {
        for (int i = 0; i < this.arrGround.Length; i++)
        {
            var groundTrans = this.arrGround[i];
            this.arrGround[i].Translate(-Vector3.up * speed * Time.deltaTime);
 
            //두장일때
            //if (groundTrans.transform.localPosition.z <= -29.5)
            //{
            //    groundTrans.transform.localPosition = new Vector3(0, 0, 30);
            //}
 
            //세장일때
            if (groundTrans.transform.localPosition.z <= -29)
            {
                groundTrans.transform.localPosition = new Vector3(0060);
            }
        }
    }
 
 
    //여기부터 자습서에서 따온것(Repeat 사용)
    private void Start()
    {
        this.movePosition = this.transform.position;
    }
 
    private void FixedUpdate()
    {
        var newPosition = Mathf.Repeat(Time.time * speed, tileSize);
        this.transform.position = this.movePosition - Vector3.forward * newPosition;
    }
}
cs


참조 : http://blog.naver.com/PostView.nhn?blogId=dus531400&logNo=140194546085&parentCategoryNo=&categoryNo=&viewDate=&isShowPopularPosts=false&from=postView

참조 : https://dawninthemoon.tistory.com/12

API : https://docs.unity3d.com/kr/530/ScriptReference/Mathf.Repeat.html