- Home /
Question by
matrix1395 · Feb 13 at 05:21 PM ·
c#positionangletouches
Can't see the angle value on the screen
I want to display the value of angle which is the value of the angle created between two lines but on the screen I see the value 0 all the time - it should be added that when I use Debug.Log the value is displayed correctly in the console and I don't know where the mistake is.
using UnityEngine;
using UnityEngine.UI;
public class TouchPosition : MonoBehaviour
{
public Text distanceText, angleText;
public float angle;
void Update()
{
//Positioning();
CheckDistance();
}
public void CheckDistance()
{
for (int i = 1; i < Input.touchCount; i++)
{
for (int j = 0; j < i; j++)
{
float dist = Vector2.Distance(Input.touches[i].position, Input.touches[j].position);
angle = Vector2.Angle(Input.touches[i-1].position - Input.touches[i].position, Input.touches[j].position - Input.touches[i].position);
Debug.Log($"Dist between touch {i} and {j} = {dist}");
Debug.Log($"Angle between touch {i-1} and {i} and {j} = {angle}");
distanceText.text = " Distance : " + dist;
angleText.text = "Angle : " + angle;
}
}
}
Comment
Do you have a NullReferenceException
in the console? If so, you forgot to assign angleText
and/or distanceText
in the inspector.