- Home /
How do I change the logged text based on a momentary collision?
I'm exporting several pieces of information about the player in a game to a text file outside of unity using the script below. I want to constantly know the player's x and z position, as well as their rotation so I can see where they're facing in the environment. I also want to know when they make a specific type of error, which, in this case, is running into a wall. When they are not running into a wall, I want 0 to be printed, and when they have run into a wall, I want 1 to be printed. Everything prints out exactly how I want it to except for the wall error, which always prints 1. Here's the script and if you have any idea why this is happening I would greatly appreciate some feedback. Thanks!
EDIT: I changed the if (wallError = false) to if(wallError == false) which constantly makes it print 0 instead of 1. I think this means the problem is in the OnCollisionEnter portion of the script, as this would result in wallError never being switched from false to true. Does anyone see a problem with that part of the script that could be causing the issue?
using UnityEngine;
using System.Collections;
public class Coordinates : MonoBehaviour {
// Use this for initialization
void Start () {
}
private string xText;
private string zText;
private string rotText;
private string errorText;
public static bool wallError = false;
void FixedUpdate () {
string path = @"/Desktop/museum/Log/coords";
xText = "\n" + transform.position.x;
zText = " , " + transform.position.z;
rotText = " , " + transform.rotation;
if (wallError = false)
errorText = " , 0 ";
else
errorText = " , 1 ";
System.IO.File.AppendAllText(path, System.String.Format("{0}{1}{2}{3}", xText, zText, rotText, errorText));
}
void OnCollisionEnter (Collider other) {
if (other.name == "Catch Wall")
wallError = true;
}
}
Answer by PAEvenson · Jul 03, 2013 at 06:42 PM
if (wallError = false)
need to be:
if (wallError == false)
Now it always prints "0" ins$$anonymous$$d of always printing "1" which I think means that there's something wrong with the OnCollisionEnter because wallError is never being switched to true.
Your answer
Follow this Question
Related Questions
Level Selection and Strange Error 0 Answers
PlayerPrefs from One App to Another. 1 Answer
Collecting Array items in order 1 Answer
Changing Boolean on collision 0 Answers