using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Recorder : MonoBehaviour {
public MainController MainCont;
public bool hasStopped;
public List<Record> Records = new List<Record>();
public Record CurrentRecord = new Record();
void FixedUpdate () {
if (MainCont.isRecording == true) {
Record ();
}
if (MainCont.isRecording == true && Records.Count >= 2 ) {
if (((Vector3.Distance (Records [0].pos, Records [1].pos) <= 0) && (Vector3.Distance (Records [0].rot, Records [1].rot) <= 0))) {
hasStopped = true;
Debug.Log ("Stopped" + Vector3.Distance (Records [0].pos, Records [1].pos) + " : " + (Vector3.Distance (Records [0].rot, Records [1].rot))); //problem is here
} else {
hasStopped = false;
}
}
if (MainCont.isWatchingReplay == true) {
Replay ();
}
}
void Record () {
CurrentRecord.pos = new Vector3 (0, 0, 0);
CurrentRecord.rot = new Vector3 (0, 0, 0);
CurrentRecord.pos = gameObject.transform.localPosition;
CurrentRecord.rot = gameObject.transform.localRotation.eulerAngles;
Records.Insert(0,CurrentRecord);
}
void Replay () {
}
}
This code is attached to the ball in a bowling game and the code near line 25 is supposed to change a variable whenever the ball stops moving. However whenever the MainCont.isRecording the hasStopped variable immediately turns to true. I tried outputting the distances myself (line 25) but the output is “0 : 0”
so it looks like the problem is in the vector3.distace not in the if statement
Please tell me if i’m using the vecter3.distance wrong or another way to do it.
Edit: Forgot to say. Yes,the ball is moving so distance 0 is incorrect