- Home /
Question by
captainjonsparrow · Jul 13, 2018 at 04:21 AM ·
androidtransformnot workingdevice
transform.position working on Unity editor but not on Android phone?
I'm using Unity version 2018.1.6f1, and I've programmed the First Person Character to zoom in for 5 seconds and zoom out for another 5 seconds afterward once the scene starts. This works fine on the Unity Editor on my laptop but does not run when I build and run it onto a phone. There aren't any errors in the adb logcat, so I'm not sure what is wrong. Below is my code:
string rrr = "E";
float counter = 0;
void Update(){
Boolean up, down = true;
counter += Time.deltaTime;
if (counter <=5 ){
rrr = "U";
}
if (counter > 5 && counter <= 10) {
rrr = "D";
}
try{
while (up && rrr.Equals("U")){
movein();
up = false;
}
while (down && rrr.Equals("D")){
moveout();
down = false;
}
}
private void movein(){
transform.position += transform.forward * 50 * Time.deltaTime;
Debug.Log("running movein");
}
private void moveout()
{
transform.position += transform.forward * -50 * Time.deltaTime;
Debug.Log("running movenout");
}
}
Comment
Answer by hexagonius · Jul 13, 2018 at 06:24 PM
sorry, that's way too complicated for my liking:
void Update()
{
if (Time.time > 10f)
return;
float move = Time.time < 5 ? 50 : -50;
transform.position += transform.forward * move * Time.deltaTime;
}