SHADE_Y3/Assets/Scripts/Gameplay/SC_JumpPad.cs

80 lines
2.2 KiB
C#

using SHADE;
using SHADE_Scripting.Audio;
using System;
public class JumpPad : Script
{
private Transform tran;
private Vector3 defaultScale;
public float scaleYMaxSize = 2.0f;
private float scaleXZMaxSize;
public float scaleDuration = 0.25f;
private bool landed = false;
private bool scaleUpDone = false;
[NonSerialized]
private TweenThread scaleYUp;
[NonSerialized]
private TweenThread scaleXZUp;
[NonSerialized]
private TweenThreadVec3 scaleDown;
protected override void awake()
{
AudioHandler.audioClipHandlers["SFXJumpPad"] = Audio.CreateAudioClip("event:/Props/jumppad_boing");
tran = GameObject.GetComponent<Transform>();
if (!tran)
Debug.LogError("NO TRANSFORM");
defaultScale = tran.LocalScale;
scaleXZMaxSize = scaleYMaxSize * 0.3f;
}
protected override void start()
{
scaleYUp = TweenManager.CreateTweenThread(scaleDuration, tran.LocalScale.y, scaleYMaxSize, EASING_METHOD.EASE_IN_SINE);
scaleXZUp = TweenManager.CreateTweenThread(scaleDuration, tran.LocalScale.y, scaleXZMaxSize, EASING_METHOD.EASE_IN_SINE);
}
protected override void update()
{
if (landed && tran)
{
tran.LocalScale = new Vector3(scaleXZUp.GetValue(), scaleYUp.GetValue(), scaleXZUp.GetValue());
if (scaleYUp.IsCompleted() && scaleXZUp.IsCompleted())
{
landed = false;
scaleUpDone = true;
scaleDown = TweenManager.CreateTweenThreadVec3(scaleDuration, tran.LocalScale, defaultScale, EASING_METHOD.EASE_IN_SINE);
}
}
if (scaleUpDone && !landed)
{
tran.LocalScale = scaleDown.GetValue();
if (scaleDown.IsCompleted())
{
scaleUpDone = false;
}
}
}
protected override void onCollisionEnter(CollisionInfo info)
{
if (info.GameObject.GetScript<PlayerController>() && info.GameObject.GetScript<PlayerController>().currentState == PlayerController.RaccoonStates.FALLING)
{
Audio.AttachAudioClipToObject(AudioHandler.audioClipHandlers["SFXJumpPad"], GameObject.EntityId);
AudioHandler.audioClipHandlers["SFXJumpPad"].Play();
info.GameObject.GetScript<PlayerController>().landedOnJumpPad = true;
landed = true;
scaleYUp.Reset();
scaleXZUp.Reset();
}
}
}