// Update is called once per frame void Update() { // handle invincibility if (isInvincible) { invincibleTimer += Time.deltaTime; // blink sprite if (invincibleTimer % 0.1f < 0.05f) { spriteRenderer.enabled = false; } else { spriteRenderer.enabled = true; } // end invincibility period if (invincibleTimer > invincibleTime) { invincibleTimer = 0.0f; isInvincible = false; spriteRenderer.enabled = true; } } // handle hit if (hit.IsHit()) { TakeDamage(hit.GetDamage()); hit.SetHit(false); } }
// Update is called once per frame void Update() { // handle game over if (lives == 0) { Destroy(gameObject); } // handle invincibility if (isInvincible) { invincibleTimer += Time.deltaTime; // blink sprite if (invincibleTimer % 0.1f < 0.05f) { spriteRenderer.enabled = false; } else { spriteRenderer.enabled = true; } // end invincibility period if (invincibleTimer > invincibleTime) { invincibleTimer = 0.0f; isInvincible = false; spriteRenderer.enabled = true; } } // handle hit if (hit.IsHit()) { TakeDamage(hit.GetDamage()); hit.SetHit(false); } // display canvas information DisplayHearts(); DisplayLives(); // Debug.Log(isInvincible); }
// Update is called once per frame void Update() { // raycast from back position RaycastHit2D hit = Physics2D.Raycast(transform.position, transform.right, length); Debug.DrawRay(transform.position, length * transform.right, Color.blue); backPosition = transform.position; frontPosition = transform.position + length * transform.right; if (hit.collider != null) { hitHasOccurred = true; // enemy or player collision if (hit.collider.tag == "Enemy" || hit.collider.tag == "Player") { // make sure enemy didn't fire laser if (hit.collider.tag != type) { // Debug.Log("hit enemy"); GenericHit genericHit = hit.collider.GetComponent <GenericHit>(); genericHit.SetHit(true, damage); } else { hitHasOccurred = false; } } // // player collision // else if (hit.collider.tag == "Player") // { // // make sure player didn't fire laser // if (type != "Player") // { // //Debug.Log("hit player"); // PlayerHitBehavior player = hit.collider.GetComponent<PlayerHitBehavior>(); // player.TakeDamage(damage); // } // else // hitHasOccurred = false; // } if (hitHasOccurred) { Destroy(gameObject); } } else { // destroy if too far out of camera bounds Vector3 viewportPosition = mainCamera.WorldToViewportPoint(backPosition); if (viewportPosition.x < -0.5f || viewportPosition.x > 1.5f) { Destroy(gameObject); } } lineRenderer.SetPosition(0, backPosition); lineRenderer.SetPosition(1, frontPosition); // Destroy(gameObject); // Debug.Log(backPosition); // Debug.Log(frontPosition); // update back position transform.position += speed * Time.deltaTime * transform.right; }