2017-01-04 4 views
1

을 반복하지하지만 여기
을 반복하지 않는 것은 스프라이트 텍스처 내가 쿼드에 텍스처를 반복합니다 연합

using UnityEngine; 
using System.Collections; 

public class Track : MonoBehaviour { 
    public float speed; 
    Vector2 Offset; 
    // Use this for initialization 
    void Start() { 

    } 

    // Update is called once per frame 
    void Update() { 
     Offset = new Vector2 (0, Time.deltaTime * speed); 

     GetComponent<Renderer>().material.mainTextureOffset = Offset; 

    } 
} 

누군가가 Offset에 값을 할당 할 때 로직 문제가

답변

-1

도와주세요 내 코드입니다. 아래 설명 : 당신은 지금 볼 수 있듯이

void Update() { 
    // Assume that Offset's value is { 2, 3 } 
    Offset = new Vector2 (0, Time.deltaTime * speed); 
    // Assume Time.DeltaTime's value is 0.12f 
    // Assume speed's value is 10 
    // Now to figure out the problem (0.12f * 10f = 1.2f) 
    // Offset's value is now 1.2f 
    GetComponent<Renderer>().material.mainTextureOffset = Offset; 
} 

, 당신은 단지마다 거의 동일합니다 값을 할당하고 있습니다. Time.DeltaTime은 프레임 간 델타 시간을 산출하기 때문에 값은 단지 약간 다를 수 있습니다. 이는 대략 0.0016f 일 수 있습니다.

그래서 분명히하기 위해 거의 상수이기 때문에 Time.DeltaTime에 의존해서는 안됩니다. 먼저 OffsetStart 또는 Awake 방법 초기화하려고 :

void Update() { 
    Offset = new Vector2(Offset[0] + (Time.DeltaTime * speed), Offset[1]); 
    GetComponent<Renderer>().material.mainTextureOffset = Offset; 
} 
: 당신의 Update 방법의 내부 그리고

void Start() { 
    Offset = GetComponent<Renderer>().material.mainTextureOffset; 
} 

을 그냥 X 값을 증가시킬 수있다