Created
October 10, 2016 20:58
-
-
Save pr00thmatic/04cae780cc00f747b0e3b3f3169ea639 to your computer and use it in GitHub Desktop.
Código del cañón: https://youtu.be/RCB41eCLRKA
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class Bullet : MonoBehaviour { | |
public float Speed = 1; | |
public float LifeTime; | |
private float _age; | |
void Start () { | |
transform.parent = null; | |
} | |
void Update () { | |
_age += Time.deltaTime; | |
this.transform.Translate(new Vector3(0, 0, Speed) * Time.deltaTime); | |
if (_age > LifeTime) { | |
Destroy(this.gameObject); | |
} | |
// transform.forward | |
// transform.left | |
// this.transform.position = this.transform.position + new Vector3(0, 0, Speed) * Time.deltaTime; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class Shooter : MonoBehaviour { | |
public float CooldownTime = 0.5f; | |
public GameObject BulletPrototype; | |
private float _timeSinceLastShot = 0; | |
void Start () { | |
} | |
void Update () { | |
_timeSinceLastShot += Time.deltaTime; | |
if (_timeSinceLastShot > CooldownTime) { | |
_timeSinceLastShot = 0; | |
GameObject clon = Instantiate(BulletPrototype); | |
clon.SetActive(true); | |
clon.transform.position = BulletPrototype.transform.position; | |
clon.transform.rotation = BulletPrototype.transform.rotation; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment