Separate Numbers ?
Hello :) I have the code where is i have two variables : thresX and thresY.
They are going back and forth and have the same number. So what I want to do is that to make them not having the exact number like -1 and -1.
**But I want to make them have like -1 and another 1.
Here is the code, maybe i need to change time or something like that?**
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ScoreTextOffset : MonoBehaviour {
public Material mainMat;
public float thresX;
public float thresY;
static float t;
public float max;
public float min;
void Start () {
thresX = mainMat.GetFloat ("_UnderlayOffsetX");
thresY = mainMat.GetFloat ("_UnderlayOffsetY");
}
void Update () {
t = Time.time;
thresX = min + Mathf.PingPong(t,max);
thresY = min + Mathf.PingPong(t,max);
mainMat.SetFloat ("_UnderlayOffsetX", thresX);
mainMat.SetFloat ("_UnderlayOffsetY", thresY);
}
}
Could you please clarify your question? It is not clear what "make them not having the exact number like -1 and -1" "But I want to make them have like -1 and another 1" means.
Okay I have 2 variables: thresX; thresY They are having the same amount from PingPong function. I want them to have separate result, like moving each of them to different directions(When first have "-1" and the second "1". I needs just one of them, to move to another direction like not from -1 to 1, but from 1 to -1.
Do you mean like this?
t = Time.time;
thresX = $$anonymous$$ + $$anonymous$$athf.PingPong(t,max);
thresY = max + $$anonymous$$athf.PingPong(t,$$anonymous$$); // switched $$anonymous$$ and max, so now it goes in the other direction
Answer by yummy81 · Feb 07, 2018 at 03:57 PM
Replace these lines of code:
thresX = min + Mathf.PingPong(t,max);
thresY = min + Mathf.PingPong(t,max);
with these:
thresX = min + Mathf.PingPong(t, max);
thresY = min + Mathf.PingPong(t, max);
thresY *= -1;
Your answer
Follow this Question
Related Questions
what exactly does Time.time do in Mathf.PingPong? 3 Answers
Mathf.SmoothStep sequence Time problem 1 Answer
Pausing a Mathf.PingPong at the ends 0 Answers
How is it possible to verify values and is they are correct activate objects ? 0 Answers
Why is Vector2.SignedAngle not working as expected? 0 Answers