I was wondering if It would be possible to do this? Sort of like how it happens in Alan wake?
I want to shine a light on an enemy, and the light makes them dissolve, I was trying to tweak this script which i have working for melee damage : but couldn’t figure out how, as i’m still learning javascript, any help?
#pragma strict
var TheDammage : int = 50;
var Distance : float;
var MaxDistance : float = 1.5;
function Update ()
{
if (Input.GetButtonDown(“Fire1”))
{
var hit : RaycastHit;
if (Physics.Raycast (transform.position, transform.TransformDirection(Vector3.forward), hit))
{
Distance = hit.distance;
if (Distance < MaxDistance)
{
hit.transform.SendMessage(“ApplyDammage”, TheDammage, SendMessageOptions.DontRequireReceiver);
}
}
}
}
A way to do this could be to check the Distance for both Melee and Flash light - like this example:
I haven’t tested this so sorry if it doesn’t work…
#pragma strict
var MeleeDamage : int = 50;
var FlashLightDamage : int = 20;
var Distance : float;
var MaxMeleeDistance : float = 1.5;
var MaxFlashLightDistance : float = 20;
function Update ()
{
var hit : RaycastHit;
if (Physics.Raycast (transform.position, transform.TransformDirection(Vector3.forward), hit))
{
Distance = hit.distance;
//Fire Required
if (Input.GetButtonDown("Fire1"))
{
//Melee
if (Distance <= MaxMeleeDistance)
{
hit.transform.SendMessage("ApplyDammage", MeleeDamage, SendMessageOptions.DontRequireReceiver);
}
}
// Fire not Required
else
{
//Flash Light
if (Distance <= MaxFlashLightDistance)
{
hit.transform.SendMessage("ApplyDammage", FlashLightDamage, SendMessageOptions.DontRequireReceiver);
}
}
}
}
Sorry OP if you actually wanted to know how to create a “larger RayCast” as A.Killingbeck has just provided… But Hopefully my addition is useful a bit.
Thanks for the help, but i want it so the light shining from it, kills the person , if you could still assist please
To do that the light ray would have to have a collider which would mean it would be an object… The easiest way is to use the RayCast like i said or a Capsule Cast (to cover a larger area) that traces the light.