IEnumerator Shoot() { RaycastHit2D hitInfo = Physics2D.Raycast(firePoint.position, firePoint.up, 15); SoundMangerScript.Playsound("laserSound"); if (hitInfo) { if (hitInfo.transform.name.Contains("Coin")) { lineRenderer.SetPosition(0, firePoint.position); lineRenderer.SetPosition(1, hitInfo.point); myPlayerControll.randomPlaceObj(hitInfo.collider, 50); } if (hitInfo.transform.name.Contains("Asteroid")) { lineRenderer.SetPosition(0, firePoint.position); lineRenderer.SetPosition(1, hitInfo.point); myPlayerControll.randomPlaceObj(hitInfo.collider, 50); } if (hitInfo.transform.name.Contains("herz")) { lineRenderer.SetPosition(0, firePoint.position); lineRenderer.SetPosition(1, hitInfo.point); myPlayerControll.randomPlaceObj(hitInfo.collider, 200); } } else { // draw line lineRenderer.SetPosition(0, firePoint.position); lineRenderer.SetPosition(1, firePoint.position + new Vector3(0, 15, 0)); } lineRenderer.enabled = true; yield return(new WaitForSeconds(0.1f)); lineRenderer.enabled = false; }
private void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.CompareTag("Coin")) { SoundMangerScript.Playsound("coinSound"); randomPlaceObj(other, 50); score++; scoreTextMesh.text = "Score: " + score.ToString(); } if (other.gameObject.CompareTag("Asteroid")) { SoundMangerScript.Playsound("crashSound"); randomPlaceObj(other, 50); leben--; lifeTextMesh.text = "Leben: " + leben.ToString(); if (leben == 0) { if (score > PlayerPrefs.GetInt("Highscore1")) { PlayerPrefs.SetInt("Highscore2", PlayerPrefs.GetInt("Highscore1")); PlayerPrefs.SetInt("Highscore1", score); PlayerPrefs.SetString("NameHigh2", PlayerPrefs.GetString("NameHigh1")); } else { if (score > PlayerPrefs.GetInt("Highscore2")) { PlayerPrefs.SetInt("Highscore3", PlayerPrefs.GetInt("Highscore2")); PlayerPrefs.SetInt("Highscore2", score); PlayerPrefs.SetString("NameHigh3", PlayerPrefs.GetString("NameHigh2")); } else { if (score > PlayerPrefs.GetInt("Highscore3")) { PlayerPrefs.SetInt("Highscore3", score); } } } PlayerPrefs.SetInt("endScore", score); SceneManager.LoadScene(2); } } if (other.gameObject.CompareTag("Herz")) { other.transform.position = new Vector2(Random.Range(-4, 4), 200); leben++; lifeTextMesh.text = "Leben: " + leben.ToString(); } if (other.gameObject.CompareTag("SpeedChange")) { switch (countSpeedColl) { case 0: speedObjects += 1; countSpeedColl++; other.transform.position = new Vector2(0, 50); break; case 1: speedObjects += 1; countSpeedColl++; other.transform.position = new Vector2(0, 100); break; case 2: speedObjects += 1; countSpeedColl++; other.transform.position = new Vector2(0, 100); break; case 3: speedObjects += 1; countSpeedColl++; other.transform.position = new Vector2(0, 120); other.gameObject.SetActive(false); break; case 4: speedObjects += 1; countSpeedColl++; other.gameObject.SetActive(false); break; } } if (other.gameObject.CompareTag("Dauerschuss")) { dauerschuss = true; randomPlaceObj(other, 200); } }