Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

script values do not change in game-view

Discussion in 'Scripting' started by sytrox, Jun 25, 2014.

  1. sytrox

    sytrox

    Joined:
    Jun 25, 2014
    Posts:
    4
    Hi folks,

    we have a problem triggering a value in a script.
    It works in the scene-view, but it is always the predefined value in the game view.

    Whats the reason for this behavior?
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. public class ToggleScript : MonoBehaviour {
    4.     public GameObject wrist;
    5.     private Vector3 oldPosition;
    6.     private CircularGravityForce.CircularGravity gravityScript;
    7.     void OnEnable() {
    8.         gravityScript = this.GetComponent<CircularGravityForce.CircularGravity>();
    9.     }
    10.    
    11.     // Update is called once per frame
    12.     void Update () {
    13.         Vector3 actualPosition = wrist.transform.position;
    14.         //Debug.Log(transform.position.x);
    15.         Vector3 direction = actualPosition - oldPosition;
    16.         float distance = direction.magnitude;
    17.         GameObject asd = wrist.transform.parent.gameObject;
    18.         float neededDistance = .2f * asd.transform.localScale.x;
    19.         //print ("Distance: '"+neededDistance+"'");
    20.  
    21.         if (distance > neededDistance)
    22.         {
    23.             if( gravityScript != null){
    24.                 Debug.Log ("Force was: '"+gravityScript.forcePower+"'");
    25.                 gravityScript.forcePower = -1.1f * gravityScript.forcePower;
    26.                 Debug.Log ("Force is: '"+gravityScript.forcePower+"'");
    27.             }else{
    28.                 Debug.Log ("nope");
    29.             }
    30.         }
    31.         oldPosition = actualPosition;
    32.     }
    33.  
    34. }
    kind regards
    sytrox
     
  2. dterbeest

    dterbeest

    Joined:
    Mar 23, 2012
    Posts:
    389
    you are seeing the Debug.Log statements in the console? What kind of output does that give?
     
  3. sytrox

    sytrox

    Joined:
    Jun 25, 2014
    Posts:
    4
    for the scene view, the value is triggered and increased correctly, but in game view the value is always the same (10)
     
  4. dterbeest

    dterbeest

    Joined:
    Mar 23, 2012
    Posts:
    389
    how do you mean "in the scene view value is triggered"??
    the update function from your code is not called in the scene view (aka when not playing the game)

    So i ask again, when you press play do you at any point see some output in the console, and what does that output say?
     
  5. sytrox

    sytrox

    Joined:
    Jun 25, 2014
    Posts:
    4

    If i press play i am entering the game view, but i can still switch back to the scene view while the game is still running.
    Everything works like expected in the scene-view, but in the game view i always get the same value.

     
  6. dterbeest

    dterbeest

    Joined:
    Mar 23, 2012
    Posts:
    389
    Ok, that is just plain weird... I am afraid i can't help you at the moment as i don't have access to Unity atm (at work)

    i'll check it out whn im home
     
  7. sytrox

    sytrox

    Joined:
    Jun 25, 2014
    Posts:
    4
    *push* can anybody replicate this problem?
    Do i need to do anythiong special if i change values from one script in another?

    EDIT: never mind, i fixed it. Problem was coused by another script which was runned after this

    kind regards
    sytrox
     
    Last edited: Jul 4, 2014