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
C-/C++-Quelltext |
|
1 2 |
/* Keep the compiler happy */ return(0); |
Community-Fossil
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 |
using UnityEngine; using System.Collections; public class BULLET_ThermalDetonator : MonoBehaviour { float lifespan = 6.0f; // Use this for initialization void Start () { } void Explode() { Destroy(gameObject); } void OnCollisionEnter(Collision collision) { Explode (); } // Update is called once per frame void Update () { lifespan -= Time.deltaTime; if(lifespan <= 0) { Explode(); } } } |
C-/C++-Quelltext |
|
1 2 |
/* Keep the compiler happy */ return(0); |
C-/C++-Quelltext |
|
1 2 |
/* Keep the compiler happy */ return(0); |
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 |
using UnityEngine; using System.Collections; public class BULLET_ThermalDetonator : MonoBehaviour { public float lifespan = 6.0f; public float force = 100.0f; public Transform playerTransform = null; private Rigidbody _rigid = null; // Use this for initialization void Start () { Invoke("Explode", lifespan); _rigid = GetComponent<Rigidbody>(); _rigid.AddForce((transform.position - playerTransform.position ).normalized * force , ForceMode.Impulse); } void Explode() { Destroy(gameObject); } void OnCollisionEnter(Collision collision) { Explode (); } } |
Dieser Beitrag wurde bereits 3 mal editiert, zuletzt von »Renegade123« (07.12.2013, 21:40)
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 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
using UnityEngine; using System.Collections; public class FP_Shooting : MonoBehaviour { enum eIsUsed { Pistole, AK47 }; eIsUsed IsUsed = eIsUsed.Pistole; public class Shooting { public Shooting (GameObject Weapon, GameObject Bullet, int magazin_max, float bulletImpulse, Texture2D Crosshair) { reload = false; this.Weapon = Weapon; this.Bullet = Bullet; this.magazin_max = magazin_max; magazin = magazin_max; Wait = 0.0f; this.bulletImpulse = bulletImpulse; this.Crosshair = Crosshair; KeyDownR = false; } public void Update (GameObject weapon) { // Fire!!! if( Input.GetButtonDown("Fire1") && reload == false ) { GameObject thebullet = (GameObject)Instantiate(Bullet, weapon.transform.position + weapon.transform.up, weapon.transform.rotation); thebullet.rigidbody.AddForce( weapon.transform.up * bulletImpulse, ForceMode.Impulse); magazin--; } if( Input.GetKeyDown (KeyCode.R) && magazin < magazin_max) KeyDownR = true; if( KeyDownR && magazin > 0 && magazin < magazin_max ) { Wait += Time.deltaTime; reload = true; if( Wait >= 5.0f ){ magazin = magazin_max; Wait = 0.0f; reload = false; KeyDownR = false; } } // If magazin is empty if( magazin <= 0 ){ Wait += Time.deltaTime; reload = true; if( Wait >= 5.0f ) { magazin = magazin_max; Wait = 0.0f; reload = false; } } } public bool reload; public GameObject Weapon; public GameObject Bullet; public int magazin_max; public int magazin; public float Wait; public float bulletImpulse; public Texture2D Crosshair; bool KeyDownR; } public GameObject bullet_prefab; public bool reload; public int magazin; public float Wait; float bulletImpulse; bool KeyDownR; public Texture2D Crosshair; public Shooting Pistole; public Shooting AK; public GameObject AKObject; // Use this for initialization void Start () { reload = false; magazin = 20; Wait = 0.0f; bulletImpulse = 60000f; KeyDownR = false; Pistole = new Shooting (GameObject.Find ("Player/Pistole"), bullet_prefab, 20, bulletImpulse, Crosshair); AK = new Shooting (GameObject.Find ("Player/AK-47"), bullet_prefab, 40, bulletImpulse-bulletImpulse+30f, Crosshair); } // Update is called once per frame void Update () { AK.Update (AKObject); } void OnGUI () { if( !AK.reload ) GUI.Box (new Rect (30, 50, AK.magazin*10, 20), AK.magazin.ToString()); if( AK.reload ) GUI.Box (new Rect(30, 50, AK.Wait*40, 20), "reloading..."); GUI.Label (new Rect((Screen.width - Crosshair.width) / 2, (Screen.height - Crosshair.height) / 2, Crosshair.width, Crosshair.height), Crosshair); } } |
C-/C++-Quelltext |
|
1 2 |
/* Keep the compiler happy */ return(0); |
Nun fliegen die Kugeln manchmal in die richtige Richtung.
Das Script das die Kugel wenn sie irgendetwas berührt zerstören sollte funktioniert allerdings nicht.
Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von »Renegade123« (07.12.2013, 23:47)
Community-Fossil
Es ist ja keine Schande etwas falsch zu machen, als Programmierer tu ich das täglich, [...].
Werbeanzeige