- Home /
Input.deltaTime always returns 0 in Xcode, working in Unity Remote app
Hey,
I am reasonably new to Unity and a Hobbyist programmer at best. I am in the middle of creating my 2nd mobile game.
I am at a frustrating point in that my game works within Unity and on the Unity Remote app in iOS, however as soon as I compile it in Xcode it refuses to work in the same way.
The point it appears to be sticking at is because I am waiting for a user to have held down a tap by updating a variable and adding Input.deltaTime. However having output this deltaTime information to a debug log it appears that deltaTime is showing up as always 0 so the function never works. Please see my code below.
Thanks in advance.
using UnityEngine;
public class TouchController : MonoBehaviour
{
//variables
enum State
{
startMode,
scopeMode,
aimMode
}
State currentState;
public CameraController2 cameraController2;
public GameObject arrowObject;
public ArrowPutterPivotController arrowPutterPivotController;
public BallController ballController;
public PutterController putterController;
private float touchStationaryTime;
private Vector2 scopeStartVector;
//functions
private void Start()
{
currentState = State.startMode;
arrowPutterPivotController.hideArrow();
}
void Update()
{
//check for input
if (Input.touchCount > 0)
{
//get first touch details
Touch touch = Input.GetTouch(0);
TouchPhase phase = touch.phase;
Debug.Log("TouchPhase: " + phase);
//check if touch has just begun
if (phase == TouchPhase.Began)
{
//reset state to normal scoping
currentState = State.startMode;
touchStationaryTime = 0f;
scopeStartVector = Vector2.zero;
arrowPutterPivotController.hideArrow();
}
//check if touch has has stayed still
if (touch.phase == TouchPhase.Stationary && currentState == State.startMode)
{
//Increase touchstationarytime by time since last touch press
Debug.Log("touch.deltaTime: " + touch.deltaTime);
touchStationaryTime += touch.deltaTime;
Debug.Log("touchStationaryTime: " + touchStationaryTime);
//Check if touch press is over 1 second
if (touchStationaryTime > 0.5f && ballController.stationary == true)
{
Debug.Log("if (touchStationaryTime > 0.5f && ballController.stationary == true)");
currentState = State.aimMode;
arrowObject.SetActive(true);
arrowPutterPivotController.showArrow();
scopeStartVector = touch.position;
}
//check time of being in stationary status
} else if (touch.phase == TouchPhase.Moved && currentState == State.startMode)
{
currentState = State.scopeMode;
}
if ((touch.phase == TouchPhase.Moved || touch.phase == TouchPhase.Stationary) && currentState == State.aimMode)
{
Vector2 diffVector;
diffVector = scopeStartVector - touch.position;
arrowPutterPivotController.setRotation(diffVector);
arrowPutterPivotController.resizeArrow(diffVector);
}
if (touch.phase == TouchPhase.Ended && currentState == State.aimMode)
{
Vector2 diffVector;
diffVector = scopeStartVector - touch.position;
putterController.hitBall(diffVector);
arrowPutterPivotController.hideArrow();
scopeStartVector = Vector2.zero;
currentState = State.startMode;
}
if (touch.phase == TouchPhase.Moved && currentState == State.scopeMode)
{
cameraController2.Spin(touch.deltaPosition);
}
}
}
}
Your answer
Follow this Question
Related Questions
xCode > testFlight 3 Answers
RenderTexture runtime error on app load on iOS 1 Answer
unity3d xcode build for iOS “object is not signed at all” 0 Answers
Iphone 4s simulator problem ? 1 Answer