Skip to content

Instantly share code, notes, and snippets.

@pr00thmatic
Created October 10, 2016 20:58
Show Gist options
  • Save pr00thmatic/04cae780cc00f747b0e3b3f3169ea639 to your computer and use it in GitHub Desktop.
Save pr00thmatic/04cae780cc00f747b0e3b3f3169ea639 to your computer and use it in GitHub Desktop.
Código del cañón: https://youtu.be/RCB41eCLRKA
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;
}
}
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