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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Script not changing boolean

Discussion in 'Animation' started by hattyh, Aug 4, 2015.

  1. hattyh

    hattyh

    Joined:
    Jul 8, 2015
    Posts:
    15
    So i have this script:
    1. #pragma strict

    2. public var IsShooting : boolean = false;

    3. function Update (){

    4. if(Input.GetButtonDown ("Fire1")){
    5. IsShooting = !IsShooting; // toggles onoff at each click
    6. if (IsShooting){
    7. print("You're shooting!");
    8. } else {
    9. print("Not shooting");
    10. }
    11. }
    12. }

    I found it on the forums as an answer, just to try it out but it's not working(doing something wrong most likely).
    So i have 2 problems.

    1- It does enable and prints "You're shooting!", but doesn't change the bool in the parameter:/
    2- I also have no clue how to make it so when i hold it, it shoots, instead of toggling. I did try changing a few things here and there like IsShooting = True; then on button release IsShooting = False; But it was constantly on. So i went back to the original script :/

    The bool's name is also "IsShooting"
    It's attached to the weapon "Mac-10" which is the gameobject with the animator and controller.

    So any help would be appreciated :D
     
  2. hattyh

    hattyh

    Joined:
    Jul 8, 2015
    Posts:
    15
    I just realised, this doesn't change the animator boolean does it? Can someone confirm that?
     
    Last edited: Aug 4, 2015
  3. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,675
  4. hattyh

    hattyh

    Joined:
    Jul 8, 2015
    Posts:
    15