FragMate CommunityLog in

FragMate - Software and Game Developer Community, including Resources, Forums, Marketplace & More.

Share

descriptionPrefab Grenade Shooting

more_horiz
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);
}
}

descriptionRe: Prefab Grenade Shooting

more_horiz
You sir deserve some respect

descriptionRe: Prefab Grenade Shooting

more_horiz
Man Cool Script!

descriptionRe: Prefab Grenade Shooting

more_horiz
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 =)

_________________
[You must be registered and logged in to see this link.]
Permissions in this forum:
You cannot reply to topics in this forum