Hi,i made script for my game,but now im bit confused,ibecause i did not everything bedore…Now i dont know how to do that.
So what i just need is : when raycast hits player then print(“massage”); and thats all (Without deleting anything from this script)
Can anyone help me,Please? Thanks. ![]()
#pragma strict
var hitInfo : RaycastHit;
var Layers : LayerMask = -1;
var TrigerLayers : LayerMask = -1;
var tr : Transform;
var Distance : float;
var BeamActive : boolean;
function Awake () {
tr = transform;
}
function Update () {
if (!BeamActive)
return;
// Cast a ray to find out the end point of the laser
if (Physics.Raycast (tr.position, tr.up, hitInfo, Mathf.Infinity, Layers)) {
Distance = hitInfo.distance;
var hits : RaycastHit[];
hits = Physics.RaycastAll (tr.position, tr.up, Distance, TrigerLayers);
for (var i = 0; i < hits.Length; i++) {
var hit : RaycastHit = hits[i];
hit.transform.gameObject.SendMessageUpwards('Lightened', null, SendMessageOptions.DontRequireReceiver);
}
}
}
function GetHitInfo () : RaycastHit {
if (!BeamActive) {
hitInfo.distance = 0.0;
}
return hitInfo;
}
function ForceRaycast() {
if (!BeamActive)
return;
Physics.Raycast (tr.position, tr.up, hitInfo, Mathf.Infinity, Layers);
}
function UpdateObject(Active : boolean) {
BeamActive = Active;
if (!Active)
hitInfo.distance = 0.0;
}