Shake obj before vanish
This commit is contained in:
parent
b95d04923c
commit
5b1d030d3d
@ -42,6 +42,8 @@ public class GrappleHook : MonoBehaviour
|
||||
private bool grappled = false, grappling = false, boosted = false, changingLength = false, isStunned = false;
|
||||
float changingLengthDir = 0;
|
||||
private Vector3 currGrappleEndPos;
|
||||
private GameObject hookedTo; // The obj we are hooked to
|
||||
public GameObject HookedTo{get => hookedTo; set => hookedTo = value;}
|
||||
|
||||
#region private methods
|
||||
void Start()
|
||||
@ -136,6 +138,7 @@ public class GrappleHook : MonoBehaviour
|
||||
if(hit.transform.tag.Equals("Vanishing")){
|
||||
hit.transform.gameObject.GetComponent<Vanisher>().Begin(this);
|
||||
}
|
||||
hookedTo = hit.transform.gameObject;
|
||||
currGrappleEndPos = transform.position;
|
||||
}
|
||||
|
||||
@ -145,6 +148,7 @@ public class GrappleHook : MonoBehaviour
|
||||
lr.enabled = false;
|
||||
boosted = false;
|
||||
Destroy(joint);
|
||||
hookedTo = this.gameObject;
|
||||
}
|
||||
|
||||
private Vector2 WorldToUI(Vector3 point){
|
||||
|
||||
@ -8,21 +8,41 @@ public class Vanisher : MonoBehaviour
|
||||
private float timeToVanish;
|
||||
[SerializeField]
|
||||
private float timeToAppear;
|
||||
private float timer = 0;
|
||||
private GrappleHook grapple;
|
||||
private bool isVanishing = false;
|
||||
private Vector3 originalPos;
|
||||
//TODO represent obj is breaking
|
||||
|
||||
private void Start() {
|
||||
originalPos = transform.localPosition;
|
||||
}
|
||||
private void Update() {
|
||||
timer += Time.deltaTime;
|
||||
if(isVanishing){//Shake
|
||||
float speed = timer / timeToVanish;
|
||||
float x = Random.Range(-.5f, .5f) * speed * .01f;
|
||||
float y = Random.Range(-.5f, .5f) * speed * .01f;
|
||||
transform.localPosition += new Vector3(x, y, originalPos.z);
|
||||
}
|
||||
|
||||
}
|
||||
public void Begin(GrappleHook grapple){
|
||||
if(isVanishing)return;
|
||||
this.grapple = grapple;
|
||||
if(isVanishing)return;
|
||||
Invoke("Vanish", timeToVanish);
|
||||
isVanishing = true;
|
||||
originalPos = transform.localPosition;
|
||||
timer = 0;
|
||||
}
|
||||
|
||||
private void Vanish(){
|
||||
grapple.Unhook();
|
||||
grapple?.Unhook();
|
||||
gameObject.SetActive(false);
|
||||
Invoke("Appear", timeToAppear);
|
||||
isVanishing = false;
|
||||
timer = 0;
|
||||
transform.localPosition = originalPos;
|
||||
}
|
||||
|
||||
private void Appear(){
|
||||
@ -34,4 +54,12 @@ public class Vanisher : MonoBehaviour
|
||||
Begin(other.gameObject.GetComponent<GrappleHook>());
|
||||
}
|
||||
}
|
||||
private void OnCollisionExit(Collision other) {
|
||||
if(other.gameObject.tag.Equals("Player")){
|
||||
if(!grapple.HookedTo.Equals(this.gameObject)){
|
||||
grapple = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user