Unity Ninja Unity 3D Forum
To have exclusive access to all downloads, recourses and links within this forum, a free registered account is required. Just a heads up Wink
Share
Go down
Member [Lv. 3]
Member [Lv. 3]
Posts : 37
Points : 1641
Rep : 19
Join date : 2014-06-14
View user profile

Easy Gun Script

on Wed Aug 06, 2014 10:28 am
Just attach this to the gun

using UnityEngine;
using System.Collections;

public class Instatinate : MonoBehaviour {

// Use this for initialization
public Rigidbody bullet;
public Transform emptygameobject;
public float distance;
public GameObject enemy;

void Start () {

}

// Update is called once per frame

void Update () {
if (Input.GetButtonDown ("Fire1")) {

Rigidbody rocketInstance;
rocketInstance = Instantiate(bullet, emptygameobject.position, emptygameobject.rotation)as Rigidbody;
rocketInstance.AddForce(emptygameobject.forward * 5000);


}
}
void myRaycast(){
RaycastHit hit;
Ray myRay = new Ray(transform.position, Vector3.forward);
if(Physics.Raycast (myRay, out hit, distance)){
if(hit.collider.tag == "enemy"){
Destroy(enemy);
}

}

}
}
Member [Lv. 1]
Member [Lv. 1]
Posts : 2
Points : 1407
Rep : 0
Join date : 2014-09-14
View user profile

Re: Easy Gun Script

on Mon Feb 02, 2015 8:26 pm
thanks helps alot cheers
Member [Lv. 1]
Member [Lv. 1]
Posts : 2
Points : 1291
Rep : 0
Join date : 2015-01-10
View user profile

Re: Easy Gun Script

on Thu Feb 05, 2015 4:40 am
ummm so i want to use this but im not sure if i need to get a bullet asset since im new so please help me!
Back to top
Permissions in this forum:
You cannot reply to topics in this forum