Hello.
I wanted to make a calculator that can calculate the amount of speed that an object will increase per frame. The main idea is that if the player’s position in an axis was 1 on the first frame, 2 in the second frame, 5 in the third frame an 8 in the 4th frame, the calculator will display that the player’s speed was 1 in the first and second frames, and 3 in the 3rd and 4th frames. I tried to code it in, but the code didn’t work. Here it is:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestScript : MonoBehaviour
{
void Update()
{
Vector3 position = transform.position;
float speedIncrement;
float Xpos = position.x;
Debug.Log(Xpos);
transform.position = position;
Xpos = 0;
}
}
What I wanted to do here is to show the increase in the frame, and then set the value back to 0 before showing the increase in the next frame. Instead, it just displayed my players x axis. I would like to know how to fix this. Thanks.