public void EnemyManagerUpdate() { foreach (GameObject Enemy in EnemyList) { if (!Enemy || !Enemy.activeSelf) { EnemyList.Remove(Enemy); continue; } Enemy.GetComponent <EnemyBase>().EnemyUpdate(); } //Update bullets shot by enemy foreach (GameObject BulletObj in BulletList) { if (!BulletObj) { BulletList.Remove(BulletObj); continue; } if (BulletObj.activeSelf) { BulletObj.GetComponent <BulletObject>().BulletObjectUpdate(); } //if (BulletObj.transform.localPosition.x > theCanvas.transform.localPosition.x + Screen.width || BulletObj.transform.localPosition.x < theCanvas.transform.localPosition.x - Screen.width || // BulletObj.transform.localPosition.y > theCanvas.transform.localPosition.y + Screen.height || BulletObj.transform.localPosition.y < theCanvas.transform.localPosition.y - Screen.height) //{ // Destroy(BulletObj); //} if ((BulletObj.transform.position - theCharacter.transform.position).magnitude > 500) { Destroy(BulletObj); } } }
// Update is called once per frame public void MainCharacterUpdate() { animator.SetInteger("states", 1); //charhealth.text = "Health : " + characterHealth.ToString() + "/" + "100"; moneytext.text = "Score : " + money.ToString(); //Debug.Log("THIS IS THE THINGY " + PlayerPrefs.GetFloat("respawntocheckpoint")); //Debug.Log("WHERE THE PLAYER IS GOING TO SPAWN " + respawnpoint); //Debug.Log("THE CHARACTER POSITION" + transform.position); //-------PROBLEMATIC CODE------// //----------------------------// //Crosshair snap to mouse position Vector3 screenPoint = Input.mousePosition; screenPoint.z = 10.0f; //distance of the plane from the camera Vector3 mousePos = Camera.main.ScreenToWorldPoint(screenPoint); gameObject.transform.GetChild(0).transform.position = mousePos; //Character faces direction of crosshair if (mousePos.x < gameObject.transform.position.x && !facingLeft) { gameObject.transform.right = -gameObject.transform.right; facingLeft = true; } else if (mousePos.x > gameObject.transform.position.x && facingLeft) { gameObject.transform.right = -gameObject.transform.right; facingLeft = false; } //Weapon Rot Vector3 normalizedDir = (mousePos - gameObject.transform.position).normalized; normalizedDir.z = 0; playerWeapon.up = normalizedDir; KeyInputs(); //Update bullets shot by player foreach (GameObject BulletObj in BulletList) { if (!BulletObj || !BulletObj.activeSelf) { BulletList.Remove(BulletObj); continue; } if (BulletObj.activeSelf) { if (BulletObj.tag == "GenericBullet") { BulletObj.GetComponent <BulletObject>().BulletObjectUpdate(); } else if (BulletObj.tag == "GenericRocket") { BulletObj.GetComponent <RocketObject>().RocketObjectUpdate(); } } //Check if out of screen if (BulletObj.transform.position.x > theCanvas.transform.localPosition.x + Screen.width || BulletObj.transform.position.x < theCanvas.transform.localPosition.x - Screen.width || BulletObj.transform.position.y > theCanvas.transform.localPosition.y + Screen.height || BulletObj.transform.position.y < theCanvas.transform.localPosition.y - Screen.height) { Destroy(BulletObj); } } //Update Character States if (characterState == CHARACTER_STATE.CHARACTERSTATE_INVINCIBLE) { InvincibilityTimer += Time.deltaTime; if (InvincibilityTimer >= InvincibilityTimeLimit) { InvincibilityTimer = 0; characterState = CHARACTER_STATE.CHARACTERSTATE_NORMAL; Destroy(gameObject.transform.Find("shield(Clone)").gameObject); } } if (isBerserk) { BerserkTimer += Time.deltaTime; if (BerserkTimer >= BerserkTimeLimit) { BerserkTimer = 0; isBerserk = false; spriteRenderer.color = defaultColour; //Modifiers BerserkDamageModifier = BerserkMovementModifer = BerserkShootSpeedModifier = 1; } } }