void FixedUpdate() { //timeCount = System.DateTime.Now.Second; //if (timeCount > 57) // timeCount -= 60; ShotScript shot = gameObject.GetComponent <ShotScript>(); HomingShotScript homingShot = gameObject.GetComponent <HomingShotScript>(); canMove = false; if (shot != null) { canMove = !shot.isEnemyShot; } if (homingShot != null) { canMove = true; } if (isTimeStopped && !canMove) { //Debug.Log("Time Stopped"); if (rigidbodyComponent == null) { rigidbodyComponent = GetComponent <Rigidbody2D>(); } rigidbodyComponent.velocity = zeroMovement; } else { //Debug.Log("Time Not Stopped"); if (rigidbodyComponent == null) { rigidbodyComponent = GetComponent <Rigidbody2D>(); } rigidbodyComponent.velocity = movement; } // Debug.Log("movement of " + gameObject.name + " = " + movement); //if (rigidbodyComponent == null) // rigidbodyComponent = GetComponent<Rigidbody2D>(); //rigidbodyComponent.velocity = movement; }
void OnTriggerEnter2D(Collider2D otherCollider) { //is this a heart? LifeItemScript lifeItem = otherCollider.gameObject.GetComponent <LifeItemScript>(); if (lifeItem != null) { if (!isEnemy) { hp++; Destroy(otherCollider.gameObject); } } // Is this a shot? ShotScript shot = otherCollider.gameObject.GetComponent <ShotScript>(); if (shot != null) { // Avoid friendly fire if (shot.isEnemyShot != isEnemy) { Damage(shot.damage); // Destroy the shot Destroy(shot.gameObject); // Remember to always target the game object, otherwise you will just remove the script if (!shot.isEnemyShot) { ScoreScript.scoreValue += 10; } } return; } HomingShotScript homingShot = otherCollider.gameObject.GetComponent <HomingShotScript>(); if (homingShot != null) { Debug.Log("homing shot hit!"); // Avoid friendly fire if (isEnemy) { Damage(homingShot.damage); // Destroy the shot Destroy(homingShot.gameObject); // Remember to always target the game object, otherwise you will just remove the script ScoreScript.scoreValue += 10; } return; } else { Debug.Log("homing shot not hit!"); } //is this an item? TimeStopScript item = otherCollider.gameObject.GetComponent <TimeStopScript>(); if (item != null && isEnemy == false) { item.StopTime(); Destroy(item.gameObject); return; } }