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. 2]
Member [Lv. 2]
Posts : 12
Points : 1354
Rep : 1
Join date : 2014-12-01
Age : 17
Location : Long Beach, CA
View user profile

Prefab Grenade Shooting

on Tue Feb 17, 2015 2:52 pm
Message reputation : 100% (1 vote)
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);
}
}
Member [Lv. 2]
Member [Lv. 2]
Posts : 9
Points : 1241
Rep : 4
Join date : 2015-04-08
View user profile

Re: Prefab Grenade Shooting

on Tue Jul 07, 2015 4:36 pm
You sir deserve some respect
Member [Lv. 1]
Member [Lv. 1]
Posts : 4
Points : 1407
Rep : 0
Join date : 2014-09-19
View user profile

Re: Prefab Grenade Shooting

on Fri Sep 18, 2015 4:33 pm
Man Cool Script!
avatar
Member [Lv. 3]
Member [Lv. 3]
Posts : 45
Points : 1397
Rep : 3
Join date : 2015-08-30
Age : 23
Location : Melbourne
View user profilehttp://jakeaquilina.weebly.com/

Re: Prefab Grenade Shooting

on Fri Sep 18, 2015 11:31 pm
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 =)
Back to top
Permissions in this forum:
You cannot reply to topics in this forum