Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by SEDBC3 · Jul 03, 2013 at 06:42 PM · collisionstringbooleanlogstatic-vars

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;
     }
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by PAEvenson · Jul 03, 2013 at 06:42 PM

  if (wallError = false) 

need to be:

  if (wallError == false) 
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image SEDBC3 · Jul 03, 2013 at 07:29 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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

How Do I Display Multiple Strings In Here? 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges