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 Ohakuma · Feb 12, 2015 at 12:39 AM · c#scripting problemvariablelogic

pubblic variable don't get change from script with OnTriggerStay

Hi everyone i am having some trouble with my scripts communication the script i link should change a variable in an other script when the player stay for 2 second on a platform everything work and no error but the variable that should get change never really change so everything outside the script doesn't work any idea why ? this is the two script first the one that should change the var on the other script called Platform the tochingPlatform variables is set in editor for every platform that has the script attached

thanks for the help i am going crazy everything work no error but can't find the logic that doesn't change the variable

List item

 using UnityEngine;
 using System.Collections;
 
 public class ShiStayRespawn : MonoBehaviour {
 
     public int touchingPlatform;
     
     public GameObject respawnController;
     public CheckPoint checkPoint;
     
 
 
     // Use this for initialization
     void Start () {
 
         respawnController = GameObject.Find("RespawnController");
         checkPoint = respawnController.GetComponent<CheckPoint>();
     
     
     }
 
     void OnTriggerEnter(Collider col)
     {
         
         checkPoint.starTimer = Time.time;
         checkPoint.nextTimer = checkPoint.starTimer + 2;
     }
 
     void OnTriggerStay(Collider col)
     {
         if(col.gameObject.CompareTag("Player"))
         {
             
             checkPoint.starTimer = Time.time;
             if (checkPoint.starTimer >= checkPoint.nextTimer && touchingPlatform == 0)
             {
                 Debug.Log("Start");
                 checkPoint.Platform = 0;
                 Debug.Log("Last Check : " + checkPoint.lastCheckPoint.ToString() + "Touchin " + touchingPlatform.ToString());
             }
             if (checkPoint.starTimer >= checkPoint.nextTimer && touchingPlatform == 1)
             {
                 Debug.Log("1");
                 checkPoint.Platform = 1;
                 checkPoint.saveState = 2;
                 Debug.Log("Last Check 2222222 : " + checkPoint.lastCheckPoint.ToString() + "Touchin " + touchingPlatform.ToString());
                 
             }
             if (checkPoint.starTimer >= checkPoint.nextTimer && touchingPlatform == 2)
             {
                 Debug.Log("End");
                 //checkPoint.lastCheckPoint = checkPoint.checkPoints[2].transform.position;
                 checkPoint.Platform = 2;
                 checkPoint.saveState = 3;
                 Debug.Log("Last Check 3333333 : " + checkPoint.lastCheckPoint.ToString() + "Touchin " + touchingPlatform.ToString());
                 
             }
         }
     }
 
     public void OnTriggerExit(Collider other)
     {
         Debug.Log(checkPoint.lastCheckPoint.ToString());
         //checkPoint.Platform = touchingPlatform;
     }
 
 
 
 
 
 }



and this is the script that should received the change value

 using UnityEngine;
 using System.Collections;
 
 public class CheckPoint : MonoBehaviour {
 
     public Vector3 lastCheckPoint ;
     public int saveState;
     public float starTimer;
     public float nextTimer;
     public GameObject[] checkPoints = new GameObject[3];
     
     public  GameObject[] lightsPlatform = new GameObject[5];
 
     public  int Platform = 0;
     
 
     // Use this for initialization
     void Start () 
     {
         checkPoints[0] = GameObject.Find("TheStart");
         checkPoints[1] = GameObject.Find("Check1");
         checkPoints[2] = GameObject.Find("TheEnd");
 
 
         saveState = 1;
         
         AssignCheckPoint(Platform);
     }
 
     void Update()
     {
         AssignCheckPoint(Platform);
         
     }
 
     public void AssignCheckPoint(int other)
     {
         lastCheckPoint = checkPoints[other].transform.position;
     }
     
 
 }
 

 
 



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 tango209 · Feb 12, 2015 at 06:05 AM

That code works fine. Are any debug messages coming through?

Put a Debug.Log in the OnTriggerEnter to make sure it's getting hit.
Make sure you tagged the 'Player'.
Make sure at least one of the objects has a rigidbody. Maker sure IsTrigger is checked in the colliders.

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 Ohakuma · Feb 12, 2015 at 06:23 AM 0
Share

that's the strange thing no debug messages at all , seems all to work fine even the debug messages works fine but if you look at the inspector while playing none of the variable involved get changed and when i make breakpoints in visual studio to debug all seems to work fine oh well i thought was some error in this code that i didn't see but it seems is fine then i will try debug all logic and see where it get lost thanks for look at the code and for thw answer tango209

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

What is Wrong With The Logic in My Variable? 2 Answers

Need help with fixing a code 1 Answer

script with individual function for each gameObject or public script variable to solve inventory system problem 1 Answer

Change 2D box collider Y values but how offset stay on same position and adjust their values. 0 Answers

How do I make a variable of type C# class? 1 Answer


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