Search Unity

how can i change the boolean to true in this case????

Discussion in 'Scripting' started by Ericmatheus, Dec 21, 2014.

  1. Ericmatheus

    Ericmatheus

    Joined:
    Aug 11, 2014
    Posts:
    68
    #pragma strict
    static var isdodge : boolean;
    var direction;
    var hit : RaycastHit;
    var estranho : GameObject;
    function Start () {
    direction = transform.TransformDirection (Vector3.up);
    isdodge = false;
    }
    function Update () {
    Debug.DrawLine (transform.position, hit.point, Color.red);
    if (Physics.Raycast ( transform.position, direction , hit,20)){
    isdodge = true;

    I'm trying to assign true when isn't colide anymore
    if (!Physics.Raycast ( transform.position, direction , hit,20)){ == does'nt work
    isdodge = false;


    i tried use else,but doen't work properly,someone could help me?
    thanks in advanced
     
  2. fire7side

    fire7side

    Joined:
    Oct 15, 2012
    Posts:
    1,819
    Either one of those things should work. You might need to do more checking to see if it's doing what you think. For instance, add a Debug.Log("raycast hit") or something in the brackets so you can see if it's actually hitting in the first place, or maybe it's hitting something all the time. You aren't testing to see what you hit. Your logic is correct, though. You don't have the end brackets, but I assume that's because you aren't showing all your code. An if/else would probably be the best in that circumstance, so it gets changed from true to false and back.
     
  3. Ericmatheus

    Ericmatheus

    Joined:
    Aug 11, 2014
    Posts:
    68
    ok thank you