void Update() { //Prevent Problem when player is scaled //fireOrigin.localScale = new Vector3(scale.x * Mathf.Sign(transform.localScale.x), scale.y, scale.z); //Don't need this anymore I think, I changed scaling player to flip it's sprite rendrerer if (gameObject.layer == LayerMask.NameToLayer("Player")) { onFire = CI.Fire; } if (gameObject.layer == LayerMask.NameToLayer("Player")) { target = new Vector3(Camera.main.ScreenToWorldPoint(Input.mousePosition).x, Camera.main.ScreenToWorldPoint(Input.mousePosition).y, 0); } fireOrigin.position = transform.position + (target - transform.position).normalized * dis; Quaternion a = (Vector3.Cross(fireOrigin.localPosition, Vector3.right).z) < 0 ? fireOrigin.rotation = Quaternion.Euler(0, 0, Vector3.Angle(fireOrigin.localPosition, Vector3.right)) : fireOrigin.rotation = Quaternion.Euler(0, 0, -Vector3.Angle(fireOrigin.localPosition, Vector3.right)); if (onFire && canShoot && container.childCount >= cadence && cadence > 0) { List <Transform> bullets = new List <Transform>(0); if (container.childCount >= cadence) { for (int i = 0; i < cadence; i++) { bullets.Add(container.GetChild(i)); } } foreach (Transform bul in bullets) { bul.GetComponent <SpriteRenderer>().sprite = originalBulletSprite; var bulletBehaviour = bul.GetComponent <bullet>(); bulletBehaviour.initialPos = transform.position; bulletBehaviour.maxDis = maxDis; bul.gameObject.SetActive(true); bul.SetParent(null); var offset = new Vector3(UnityEngine.Random.Range(-offsetX, offsetX), UnityEngine.Random.Range(-offsetY, offsetY)); bulletBehaviour.launch(bulletSpeed, ((target - transform.position).normalized + offset).normalized, gravityScale, bulletCost, bulletDamage); } canShoot = false; StartCoroutine(shoot(deadTime)); //Some effects with this SS.CameraTwerk(shakeMagnitude, shakeDuration, shakeFrequency); AM.PlaySoundWithpitch("shot", UnityEngine.Random.Range(0.7f, 1.3f), 1f); } }
public void onHit(float damage, Transform target) { SS.CameraTwerk(screenShake.x, screenShake.y, screenShake.z); currentEnergy -= damage; sr.color = hitColor; if (currentEnergy <= 0 && !isDead) { bigPointDrop(target); isDead = true; } else if (currentEnergy > 0) { dropPoint(target); } StartCoroutine(colorChange(timeofColorChange)); if (timeofSecurity > 0) { originalLayer = gameObject.layer; gameObject.layer = LayerMask.NameToLayer("secure"); StartCoroutine(sec(timeofSecurity)); } }