Quantcast
Viewing latest article 5
Browse Latest Browse All 70

Why are both seperate scripts being called together?

I have a script named weapon (default weapon of fists) attached to my fists object so that my fists can do a certain amount of damage and execute certain kinds of fist animations/sounds. Then I made a script called maceProperties which has pretty much the same code but tweaked to have mace sounds, animation and damage. My issue is that when using either script such as just the fists or just the mace, both scripts get called. So my debug log for either script shows that the mace is hitting as well as the fists. Is this because I have if Fire1 called in Update for both? If so, how would I use something like OnEnable to disable one when the other is being used? Here is the weapon script for the fists, the mace one behaves in a similar manner, just with their own animations and sounds. Each object has their respective scripts attached to them. #pragma strict var theDamage : int = 50;//damage of a weapon private var distance : float;//assings the actual distance between an object we are hitting var maxDistance : float = 1.5;//how far weapon hits var theAnimator : Animator;//insert the prop that has the animations from the animator var damageDelay : float = 0.6; //time before the weapon actually hits var punchHit : AudioClip; //when damage is done to something var punchObject : AudioClip;//for when an object is hit private var counter : int = 0; private var hitLeftStreak = 0;//control they don't go out in a streak, randomize hits of animation private var hitRightStreak = 0; function Update () { if(Input.GetButtonDown("Fire1")){ AttackDamage(); } } function AttackDamage(){ //Audio for Punch Miss //audio.Play(); if(Random.value >= 0.5 && hitRightStreak <= 2){ theAnimator.SetBool("PunchRight", true); hitRightStreak += 1; hitLeftStreak = 0; } else{ if(hitLeftStreak <= 2){ theAnimator.SetBool("PunchLeft",true); hitRightStreak = 0; hitLeftStreak += 1; } else{ theAnimator.SetBool("PunchRight",true); hitRightStreak += 1; hitLeftStreak = 0; } } yield WaitForSeconds(damageDelay);//does the delay //Actual Atacking var hit : RaycastHit; var ray = Camera.main.ScreenPointToRay(Vector3(Screen.width/2, Screen.height/2,0)); if(Physics.Raycast (ray,hit)){ distance = hit.distance; if(distance < maxDistance){ //hit.transform.SendMessage("ApplyDamage", theDamage, SendMessageOptions.DontRequireReceiver); audio.clip = punchHit; audio.volume = 0.60; audio.Play(); Debug.Log("Audio SHould Play"); } else{ Debug.Log("Player Missed"); } } theAnimator.SetBool("PunchRight", false);//changes are animator bool to false for punch right animation theAnimator.SetBool("PunchLeft", false); Debug.Log("Player Attacked With Fists"); }

Viewing latest article 5
Browse Latest Browse All 70

Trending Articles