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

You are not connected. Please login or register

Unity Ninja Unity 3D Forum » FREE Project Downloads & Recources » Scripts » Prefab Grenade Shooting

Prefab Grenade Shooting

View previous topic View next topic Go down  Message [Page 1 of 1]

1 Prefab Grenade Shooting on Tue Feb 17, 2015 2:52 pm

VicTore UpZombieZ


Member [Lv. 2]
Member [Lv. 2]
Made this myself Smile


#pragma strict
var Grenade : Rigidbody;
var Speed = 20;

function Update () {
if (Input.GetKeyDown (KeyCode.G))
{
var clone = Instantiate(Grenade, transform.position, transform.rotation);
clone.velocity = transform.TransformDirection(Vector3(0, 0, Speed));

Destroy (clone.gameObject, 3);
}
}

View user profile

2 Re: Prefab Grenade Shooting on Tue Jul 07, 2015 4:36 pm

Outboundstream4


Member [Lv. 2]
Member [Lv. 2]
You sir deserve some respect

View user profile

3 Re: Prefab Grenade Shooting on Fri Sep 18, 2015 4:33 pm

metaldc4life


Member [Lv. 1]
Member [Lv. 1]
Man Cool Script!

View user profile

4 Re: Prefab Grenade Shooting on Fri Sep 18, 2015 11:31 pm

aquilinajake


Member [Lv. 3]
Member [Lv. 3]
instead of destroying the gameobjects you can also use it to deal damage in a radius. depending on how big the map is their are some really easy ways to do this.

add a sphere collider to the grenade make it a trigger, and you can do something like this

//for a trigger attatched to the prefab, it is more in depth but this is general understanding

if(col.tag == "Player")
col.GetComponenet<HealthScript>().health -= damage;

//you may also need to do a foreach loop or can just do a foreach loop, store an array of players when the game is started, or a List preferably because players can leave game etc Lists are dynamic and easier to work with in that sense.

you can do something like this

Code:


foreach(GameObject player in GameManager.GetComponenet<PlayerList>())
{
if(Vector3.Distance(transform.position,GameManager.GetComponenet<PlayerList>().transform.position) < explosiveDistance)

{
GameManager.GetComponenet<PlayerList>().GetComponent<HealthSCript>().health -= Damage;
}
}



hope this helps edit things =)

View user profile http://jakeaquilina.weebly.com/

View previous topic View next topic Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum