|
|
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
-
- using BansheeGz.BGSpline.Components;
- using BansheeGz.BGSpline.Curve;
-
- public class Catapult : MonoBehaviour
- {
- public BGCurve splineCurve;
- public float speed = 600f;
- public float rotateSpeed = 200f;
- public float timePadding = 0.5f;
- public float timeBetweenLaunches = 0.5f;
- public float minScale = 0.3f;
- public float maxScale = 1f;
- public float randomFactor = 50f;
- public AnimationCurve animationCurve;
- public Transform player;
-
- private bool isLaunching = false;
- private BGCcCursor splineCursor;
- private BGCcCursorObjectTranslate splineObjectTranslate;
- private Vector3 originalScale;
- private MeshRenderer meshRenderer;
-
- void Start ()
- {
- splineCursor = splineCurve.GetComponent<BGCcCursor>();
- splineObjectTranslate = splineCurve.GetComponent<BGCcCursorObjectTranslate>();
- meshRenderer = splineObjectTranslate.ObjectToManipulate.GetComponent<MeshRenderer>();
- meshRenderer.enabled = false;
-
- originalScale = splineCurve.transform.parent.localScale;
-
- NotificationServer.register("statechange Searchlight", searchlightStateChanged);
- }
-
- void Update()
- {
- splineObjectTranslate.ObjectToManipulate.Rotate(Vector3.forward, Time.deltaTime * rotateSpeed);
- }
-
- public void searchlightStateChanged()
- {
- LeanTween.cancel(splineObjectTranslate.ObjectToManipulate.parent.gameObject, true);
- if (Searchlight.state == Searchlight.SearchState.Chasing)
- launchBoulder();
- }
-
- public void launchBoulder()
- {
- if (Searchlight.state != Searchlight.SearchState.Chasing || isLaunching)
- {
- isLaunching = false;
- return;
- }
-
- isLaunching = true;
- LeanTween.delayedCall(splineObjectTranslate.ObjectToManipulate.parent.gameObject, timeBetweenLaunches, ()=>{
- if (Searchlight.state != Searchlight.SearchState.Chasing)
- {
- isLaunching = false;
- return;
- }
- meshRenderer.enabled = true;
- splineCursor.DistanceRatio = 0f;
- splineCurve.transform.parent.position = player.position
- + Vector3.right * Random.Range(-randomFactor, randomFactor)
- + Vector3.forward * Random.Range(-randomFactor, randomFactor);
- splineCurve.transform.parent.localEulerAngles = Vector3.up * Random.Range(0f, 360f);
- splineCurve.transform.parent.localScale = new Vector3(Random.Range(minScale * originalScale.x, maxScale * originalScale.x), originalScale.y, originalScale.z);
- LeanTween.value(splineObjectTranslate.ObjectToManipulate.gameObject, 0f, 1f, splineCursor.Math.GetDistance() / speed)
- .setEase(animationCurve)
- .setOnUpdate((float val)=>{
- splineCursor.DistanceRatio = val;
- }).setOnComplete(()=>{
- splineCursor.DistanceRatio = 0f;
- isLaunching = false;
- meshRenderer.enabled = false;
- launchBoulder();
- });
- });
- }
- }
|