/// <summary> /// Reflects the argument Laser beam and emits a new Laser beam that /// passes through. /// </summary> /// <param name="sender">The sender of the event, ignored here.</param> /// <param name="args">The EventArgs object that describes the event.</param> public void OnLaserHit(object sender, HitEventArgs args) { if (args == null) { throw new ArgumentNullException("args"); } if (!args.IsValid) { throw new ArgumentException("The supplied HitEventArgs object is invalid."); } // Create a new ray coming out of the other side with the same direction // as the original ray. Forward needs to be negative, see LaserEmitter. var passThroughEmitter = this.PassThroughEmitter.GetEmitter(args.Laser); passThroughEmitter.transform.position = args.Point + (args.Laser.Direction * 0.1f); passThroughEmitter.transform.forward = -args.Laser.Direction; LaserProperties propertiesPre = args.Laser.Emitter.GetComponent <LaserProperties>(); LaserProperties propertiesPost = passThroughEmitter.GetComponent <LaserProperties>(); propertiesPost.RGBStrengths = propertiesPre.RGBStrengths / 2; // Create the second ray, reflecting off surface like a mirror Mirror.CreateReflection(args.Laser, args.Normal); }
/// <summary> /// Reflects the argument Laser beam and emits a new Laser beam that /// passes through. /// </summary> /// <param name="sender">The sender of the event, ignored here.</param> /// <param name="args">The EventArgs object that describes the event.</param> public void OnLaserHit(object sender, HitEventArgs args) { if (args == null) { throw new ArgumentNullException("args"); } if (!args.IsValid) { throw new ArgumentException("The supplied HitEventArgs object is invalid."); } // Create a new ray coming out of the other side with the same direction // as the original ray. Forward needs to be negative, see LaserEmitter. var passThroughEmitter = this.PassThroughEmitter.GetEmitter(args.Laser); passThroughEmitter.transform.localScale = new Vector3(0.2f, 0.2f, 0.2f); this.Hit = true; passThroughEmitter.transform.position = args.Point + (args.Laser.Direction * 0.1f); passThroughEmitter.transform.forward = -args.Laser.Direction; LaserProperties propertiesPre = args.Laser.Emitter.GetComponent <LaserProperties>(); LaserProperties propertiesPost = passThroughEmitter.GetComponent <LaserProperties>(); propertiesPost.RGBStrengths = propertiesPre.RGBStrengths; }
public void Reset(LaserProperties properties, ShotInfo info, Vector3 direction) { this.properties = properties; this.shotInfo = info; this.direction = direction; hitInfo.HasHit = false; flewnDistance = 0f; renderer.enabled = true; }
/// <summary> /// Creates a new LaserEmitter that emits the same type of Laser beam /// as the provided one. /// <para> /// The LaserEmitter is created as a separate game object and /// added as a child of this game object. /// </para> /// <para> /// To save resources, it is recommended to call <see cref="MultiEmitter.GetEmitter"/> /// instead, which re-uses existing LaserEmitters. However, this method can be called /// to create LaserEmitters beforehand. /// </para> /// </summary> /// <param name="laser">The original Laser beam.</param> /// <returns>The created LaserEmitter.</returns> public LaserEmitter CreateEmitter(LaserBeam laser) { GameObject emitterObject = new GameObject("Emitter"); emitterObject.transform.parent = this.gameObject.transform; VolumeLineRenderer renderer = emitterObject.AddComponent <VolumeLineRenderer>(); LaserEmitter emitter = emitterObject.AddComponent <LaserEmitter>(); LaserProperties prop = emitterObject.AddComponent <LaserProperties>(); ApplyProperties(renderer, laser, prop); return(emitter); }
private void Start() { properties = new LaserProperties { damage = damage, reach = reach, velocity = velocity }; info = new ShotInfo { shotBy = transform.root.gameObject, shotDirection = shotDirection }; }
/// <summary> /// Applies the properties from the given Laser to the VolumeLineRenderer. /// </summary> /// <param name="renderer">The VolumeLineRenderer to configure.</param> /// <param name="laser">The Laser beam to use as template.</param> /// <param name="prop">The LaserProperties describing the Laser beam.</param> /// <returns>The configured LineRenderer.</returns> public static VolumeLineRenderer ApplyProperties(VolumeLineRenderer renderer, LaserBeam laser, LaserProperties prop) { if (renderer == null) { throw new ArgumentNullException("renderer"); } if (laser == null) { throw new ArgumentNullException("laser"); } if (prop == null) { throw new ArgumentNullException("prop"); } renderer.UseWorldSpace = true; renderer.LineMaterial = laser.Emitter.LineRenderer.LineMaterial; renderer.ReceiveShadows = false; renderer.CastShadows = false; prop.RGBStrengths = laser.Emitter.Properties.RGBStrengths; return(renderer); }