Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
Administrator
Administrator
C#-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
using UnityEngine; using System.Collections; using System; public class EnemyBehaviour : MonoBehaviour { public AudioClip shootsound; public GameObject laserPrefab; public Transform spawnPoint; public float PlayerOnexPos; public float EnemyPOS; public bool inRange = false; public float laserSpeed = 500f; public float Distanz; public bool lookleft = true; public float dist; void FixedUpdate() { PlayerOnexPos = GameObject.FindGameObjectWithTag("Player").transform.position.x; // PlayerTwoxPos = GameObject.FindGameObjectWithTag("Enemy").transform.position.x; EnemyPOS = gameObject.transform.position.x; PlayerOnexPos = Mathf.Round(PlayerOnexPos); dist = (EnemyPOS - PlayerOnexPos); Distanz = (Mathf.Round(Mathf.Abs(dist))); if (Distanz <= 3) { inRange = true; shoot(); // InvokeRepeating("shoot",0.5f, 0.4f); if ((dist > 0)) { lookleft = true; } else { lookleft = false; } } else { inRange = false; } } public void Flip() { lookleft = !lookleft; Vector3 myscale = transform.localScale; myscale.x *= -1; transform.localScale = myscale; } void shoot() { Vector3 PlayerPOS = GameObject.FindGameObjectWithTag("Player").transform.position; Vector3 target = new Vector3(PlayerPOS.x, PlayerPOS.y+1.25f, PlayerPOS.z); { GameObject laser = (GameObject)Instantiate(laserPrefab, spawnPoint.position, Quaternion.identity); laser.GetComponent<Rigidbody2D>().AddForce((target - spawnPoint.position) * laserSpeed); AudioSource.PlayClipAtPoint(shootsound, transform.position, 1); } } //private IEnumerator MyEvent() //{ // while (true) // { // yield return new WaitForSeconds(0.5f); // wait half a second // shoot(); // } //} } |
C#-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
void FixedUpdate() { PlayerOnexPos = GameObject.FindGameObjectWithTag("Player").transform.position.x; // PlayerTwoxPos = GameObject.FindGameObjectWithTag("Enemy").transform.position.x; EnemyPOS = gameObject.transform.position.x; PlayerOnexPos = Mathf.Round(PlayerOnexPos); dist = (EnemyPOS - PlayerOnexPos); Distanz = (Mathf.Round(Mathf.Abs(dist))); if (Distanz <= Feindreichweite ) { inRange = true; if (zeit > Takt) zeit = 1; if (zeit == Takt) { shoot(); zeit = 1; } else { zeit += 1; } if ((dist > 0) && !lookleft) { Flip(); lookleft = true; } if ((dist < 0) && lookleft ) { Flip(); lookleft = false; } } else { inRange = false; zeit = 1; } } |
Werbeanzeige