Search Unity

Freeze Camera

Discussion in 'Scripting' started by Unity_gamer, Sep 23, 2011.

  1. Unity_gamer

    Unity_gamer

    Joined:
    Aug 19, 2011
    Posts:
    30
    Hi all,

    I am trying to develop a FPS game.I did create weapon for the player, and i have done it by adding a 2nd camera to the Weapon separately like Two layers.Now i need to Freeze the movement and the rotation of the player while it is using the Weapon(During Mouse click Weapon animation will play during that time i need to freeze the movement).I did search for that and tried different steps but nothing seems to be Working.
    Basically What i need to do is
    -During Mouse Click the Weapon animation has to play(this step is working)
    -While animation is playing(the weapon am using is a driller,during Mouse click the Drilling animation will play that time if i try to move the weapon it have to stand still)

    What can i do to make that happen..
    Thanks for any Help..:D
     
  2. ar0nax

    ar0nax

    Joined:
    May 26, 2011
    Posts:
    485
    make a bool variable, which will become true when you are using your weapon, and check in the main cam script if(!usingWeapon){//do code} and the same thing in character movement script.
     
  3. Unity_gamer

    Unity_gamer

    Joined:
    Aug 19, 2011
    Posts:
    30
    I did like this.I tried to disable the Mouse look and FPS controller code.
    Code (csharp):
    1.  
    2.             MouseLook Mouselookscript;
    3.             Mouselookscript = GetComponent<MouseLook>();
    4.             Mouselookscript.enabled = false;
    5.             FPSInputController FPSscript;
    6.             FPSscript = GetComponent<FPSInputController>();
    7.             FPSscript.enabled = false;
    8.  
    I gave this code During Weapon fire.But it seems Nothing is Working.Code is Not disabling.
    Player can still rotate during fire animation.
    What else i can do to Freeze the camera?Sample code may Help ..
    And am getting this Error also
    "NullReferenceException: Object reference not set to an instance of an object"
     
    Last edited: Sep 24, 2011
  4. Unity_gamer

    Unity_gamer

    Joined:
    Aug 19, 2011
    Posts:
    30
    The the whole code and this is the exact error that am getting.
    Code (csharp):
    1.  if (Input.GetButtonDown("Fire1"))
    2.         {
    3.        
    4.             animation.Play("Weap_Hammer");
    5.             Debug.Log("Fire1");
    6.             GetComponent<MouseLook>().enabled = false;
    7.             GetComponent<FPSInputController>().enabled = false;
    8.  
    9.         }
    10.  
    This is the Error message
    NullReferenceException: Object reference not set to an instance of an object
    Drilling.Update () (at Assets/Script/Drilling.cs:28)
     
  5. ar0nax

    ar0nax

    Joined:
    May 26, 2011
    Posts:
    485
    are you sure the MouseLook script and FPSInputController are on the object you wanna disable them from, and also make sure there is an animation on that same object, that is named "Weap_Hammer".

    You get null reference errors when you are trying to access something that has a null value (was not set, does not exist etc).
     
  6. Unity_gamer

    Unity_gamer

    Joined:
    Aug 19, 2011
    Posts:
    30
    Thanks alot For the Reply,

    Animation and every thing is fine in here.The error is happening on the following code only.
    Code (csharp):
    1.  
    2. GetComponent<MouseLook>().enabled = false;
    3. GetComponent<FPSInputController>().enabled = false;
    4.  
    That was used here to disable the FPS Input controller code and MouseLook code.This is what i am trying to do. While animation is working i want to disable all the movements of the Player.Is there any Alternate way to Achieve this?
    Thanking you...