Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class LaserProc : MonoBehaviour {
- public float Range = 10.0f;
- public float TickCount = 5.0f;
- float curTick = 0.0f;
- bool IsShooting = false;
- public void ToggleFire(bool option) {
- IsShooting = option;
- }
- Transform lastobject;
- // Update is called once per frame
- void Update () {
- if (IsShooting) {
- // did we collide with Minable
- if (Check (transform.position, transform.rotation*transform.position*Range, "Minable")) {
- // hitting the same object now
- if (lastobject != hit.transform) {
- //reset counter
- curTick = 0;
- lastobject = hit.transform;
- }
- curTick += Time.deltaTime;
- // pulse delay reached?
- if (curTick >= TickCount) {
- MinableObject script = hit.transform.GetComponent<MinableObject>();
- // has MinableObject script attached?
- if (script) {
- Debug.Log("Mined "+hit.name);
- // proc Mine(Transform parent) function in objects script
- script.Mine(transform);
- } else {
- // not a minable object
- }
- }
- } else {
- // nothing hit
- lastobject = null;
- curTick = 0;
- }
- }
- }
- // returns true if collision with map is detected
- bool Check(Vector3 begin, Vector3 target, string Tag) {
- RaycastHit hit;
- if (Physics.Raycast(begin, (target-begin), out hit, (target-begin).magnitude))
- if (hit.collider.gameObject.tag == Tag)
- return true;
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment