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..
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.
I did like this.I tried to disable the Mouse look and FPS controller code. Code (csharp): MouseLook Mouselookscript; Mouselookscript = GetComponent<MouseLook>(); Mouselookscript.enabled = false; FPSInputController FPSscript; FPSscript = GetComponent<FPSInputController>(); FPSscript.enabled = false; 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"
The the whole code and this is the exact error that am getting. Code (csharp): if (Input.GetButtonDown("Fire1")) { animation.Play("Weap_Hammer"); Debug.Log("Fire1"); GetComponent<MouseLook>().enabled = false; GetComponent<FPSInputController>().enabled = false; } This is the Error message NullReferenceException: Object reference not set to an instance of an object Drilling.Update () (at Assets/Script/Drilling.cs:28)
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).
Thanks alot For the Reply, Animation and every thing is fine in here.The error is happening on the following code only. Code (csharp): GetComponent<MouseLook>().enabled = false; GetComponent<FPSInputController>().enabled = false; 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...