void Start() { hitOnce = false; //Setting references levelManagerRef = FindObjectOfType <LevelManager>(); controller = GetComponentInParent <RTCTankController>(); body = controller.gameObject.GetComponent <Rigidbody>(); animator = GetComponentInParent <Animator>(); specialHasFired = false; reloadComplete = false; // Checking if the UI compnents are present if (!loadoutPanel || !reloadImage) // nothing to update { loadoutPanel = FindObjectOfType <Loadoutpanel>(); // Find the loadout panel and if not null, refill image if (loadoutPanel) { reloadImage = loadoutPanel.fillBarImage; } } if (loadoutPanel && !loadoutPanel.specialButton) { loadoutPanel.specialButton = loadoutPanel.transform.parent.Find("SpecialAttackBTN").GetComponent <Button>(); } // Define variables massBackup = body.mass; dragBckup = body.drag; angularDragBackup = body.angularDrag; timerStomp = coolDownStomp; timerLunge = coolDownLunge; timerSwipe = coolDownSwipe; timerBite = coolDownBite; timerSonicBoom = coolDownSonicBoom; // if animator exists, turn it off. Will enable in code when needed. if (animator) { animator.enabled = false; } if (BiteObj) { BiteObj.SetActive(false); BiteAnim.enabled = false; } if (StegoSwipe) { StegoSwipe.SetActive(false); } }
void Update() { if (!APP.IsReady) { return; } // Bounce out if this tank is AI if (controller.isAI) { return; } if (!loadoutPanel || !reloadImage) { loadoutPanel = FindObjectOfType <Loadoutpanel>(); if (loadoutPanel) { reloadImage = loadoutPanel.fillBarImage; } } if (loadoutPanel && !loadoutPanel.specialButton) { loadoutPanel.specialButton = loadoutPanel.transform.parent.Find("SpecialAttackBTN").GetComponent <Button>(); } if (lunge) // If lunge is true, updating the animations for the sepcial attack and the icons { lunge = false; timerLunge = 0; specialHasFired = true; reloadComplete = false; StartCoroutine(LungeAnimation()); } else if (controller.currentDino == dino.Tricera) { timerLunge += Time.deltaTime; if (timerLunge >= coolDownLunge) // restoring the cool down { timerLunge = coolDownLunge; reloadComplete = true; if (reloadImage) // will fill the cooldown bar with the appropriate color { reloadImage.fillAmount = coolDownLunge; reloadImage.color = Color.green; } if (loadoutPanel.specialButton.isActiveAndEnabled) { if (loadoutPanel.specialButtonAnimator) { loadoutPanel.specialButtonAnimator.SetBool("IsReady", true); } loadoutPanel.SetSpecialAttackBadge(controller.currentDino); specialHasFired = false; } } else { reloadImage.fillClockwise = true; reloadImage.fillAmount = timerLunge / coolDownLunge; } // Changing colors of the cooldown bar based on the fill amounts if (reloadImage.fillAmount >= 0.75) { reloadImage.color = Color.green; } else if (reloadImage.fillAmount > 0.25) { reloadImage.color = Color.yellow; } else if (reloadImage.fillAmount < 0.25) { reloadImage.color = Color.red; } } //if swipe is true if (swipe) { swipe = false; timerSwipe = 0; specialHasFired = true; reloadComplete = false; StartCoroutine(StegoSwipeAnimation()); } else if (controller.currentDino == dino.Stego && reloadImage || controller.currentDino == dino.Kentrosaurus && reloadImage) { timerSwipe += Time.deltaTime; if (timerSwipe >= coolDownSwipe) { timerSwipe = coolDownSwipe; reloadComplete = true; if (reloadImage) { reloadImage.fillAmount = coolDownLunge; reloadImage.color = Color.green; } if (loadoutPanel.specialButton.isActiveAndEnabled) { if (loadoutPanel.specialButtonAnimator) { loadoutPanel.specialButtonAnimator.SetBool("IsReady", true); } loadoutPanel.SetSpecialAttackBadge(controller.currentDino); specialHasFired = false; } } else { reloadImage.fillClockwise = true; reloadImage.fillAmount = timerSwipe / coolDownSwipe; } if (reloadImage.fillAmount >= 0.75) { reloadImage.color = Color.green; } else if (reloadImage.fillAmount > 0.25) { reloadImage.color = Color.yellow; } else if (reloadImage.fillAmount < 0.25) { reloadImage.color = Color.red; } } //If stomp is true if (stomp) { stomp = false; timerStomp = 0; specialHasFired = true; reloadComplete = false; Instantiate(StompObj, controller.transform.position, controller.transform.rotation); } else if (controller.currentDino == dino.Bronto) { timerStomp += Time.deltaTime; if (timerStomp >= coolDownStomp) { timerStomp = coolDownStomp; reloadComplete = true; if (reloadImage) { reloadImage.fillAmount = coolDownLunge; reloadImage.color = Color.green; } if (loadoutPanel.specialButton.isActiveAndEnabled) { if (loadoutPanel.specialButtonAnimator) { loadoutPanel.specialButtonAnimator.SetBool("IsReady", true); } loadoutPanel.SetSpecialAttackBadge(controller.currentDino); specialHasFired = false; } } else { reloadImage.fillClockwise = true; reloadImage.fillAmount = timerStomp / coolDownStomp; } if (reloadImage.fillAmount >= 0.75) { reloadImage.color = Color.green; } else if (reloadImage.fillAmount > 0.25) { reloadImage.color = Color.yellow; } else if (reloadImage.fillAmount < 0.25) { reloadImage.color = Color.red; } } // If bite is true if (bite) { bite = false; timerBite = 0; specialHasFired = true; reloadComplete = false; Instantiate(stompTrigger, stopTriggerPosition.position, stopTriggerPosition.rotation, transform.parent); StartCoroutine(BiteAnimation()); } else if (controller.currentDino == dino.Trex) { timerBite += Time.deltaTime; if (timerBite >= coolDownBite) // restoring { timerLunge = coolDownLunge; reloadComplete = true; if (reloadImage) { reloadImage.fillAmount = 0; } if (loadoutPanel) { if (reloadImage) { reloadImage.fillAmount = coolDownLunge; reloadImage.color = Color.green; } if (loadoutPanel.specialButton.isActiveAndEnabled) { if (loadoutPanel.specialButtonAnimator) { loadoutPanel.specialButtonAnimator.SetBool("IsReady", true); } loadoutPanel.SetSpecialAttackBadge(controller.currentDino); specialHasFired = false; } } } else { reloadImage.fillClockwise = true; reloadImage.fillAmount = timerBite / coolDownBite; } if (reloadImage.fillAmount >= 0.75) { reloadImage.color = Color.green; } else if (reloadImage.fillAmount > 0.25) { reloadImage.color = Color.yellow; } else if (reloadImage.fillAmount < 0.25) { reloadImage.color = Color.red; } } // If sonicboom is true if (sonicboom) { Debug.Log("SonicBoom in Update"); sonicBoomEffect.SetActive(true); sonicboom = false; timerSonicBoom = 0; specialHasFired = true; reloadComplete = false; Instantiate(sonicBoomEffect, sonicBoomTrigger.position, sonicBoomTrigger.rotation, transform.parent); } else if (controller.currentDino == dino.Duckbill) { timerSonicBoom += Time.deltaTime; if (timerSonicBoom >= coolDownSonicBoom) { timerSonicBoom = coolDownSonicBoom; reloadComplete = true; if (reloadImage) { reloadImage.fillAmount = 0; } if (loadoutPanel) { if (reloadImage) { reloadImage.fillAmount = coolDownSonicBoom; reloadImage.color = Color.green; } if (loadoutPanel.specialButton.isActiveAndEnabled) { if (loadoutPanel.specialButtonAnimator) { loadoutPanel.specialButtonAnimator.SetBool("IsReady", true); } loadoutPanel.SetSpecialAttackBadge(controller.currentDino); specialHasFired = false; } } } else { reloadImage.fillClockwise = true; reloadImage.fillAmount = timerSonicBoom / coolDownSonicBoom; } if (reloadImage.fillAmount >= 0.75) { reloadImage.color = Color.green; } else if (reloadImage.fillAmount > 0.25) { reloadImage.color = Color.yellow; } else if (reloadImage.fillAmount < 0.25) { reloadImage.color = Color.red; } } }