Unity Simple Bullet

Stream line your weapon creation. This is a work in progress, needs scriptable bullets and support for 3d models of weapons. Along with a lot of other things.

Note: You have to add a RigidBody to one of the objects you want to check collisions or triggers with. (Either the targets/enemies or bullets)

  • Put this script on your bullet object, set collider to trigger and set it’s TAG to bullet.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

// TODO make pool

public class PlayerBullet : MonoBehaviour {

	public float lifeTime = 10f;
	public float speed = 1f;

	// Use this for initialization
	void Start () {
		Destroy(gameObject, lifeTime);
	}

	// Update is called once per frame
	void Update () {
		transform.Translate(0, 0, speed * Time.deltaTime);
	}
}


  • Inside your enemy or target put this script.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BulletCollision : MonoBehaviour {

	void OnTriggerEnter(Collider other) {
		Debug.Log ("Trigger Entered");

		// check if tagged as "bullet"
		if(other.CompareTag("bullet")){
			// to Destroy Other Game Object
			Destroy(other.gameObject);
			// to Destroy Self
			Destroy(gameObject);
		}


	}
}


  • Vector Maths - Unity Official Tutorials

    Vector Maths - Unity Official Tutorials