springjoint2d - how to reset without starting new scene
i'm using the code from the angry birds tutorial, but i want to reset the slingshot without having to restart the level. when this happens GetComponent().isKinematic = false;
the spring goes away how do i get it back?
Answer by rettichmann · Dec 21, 2016 at 10:29 AM
Maybe you could use: SpringJoint2D.dampingRatio
The spring will oscillate with a certain frequency as it attempts to reestablish the desired distance between the objects. The higher the damping ratio, the quicker the oscillation will die down to zero.
Maybe you could go with something like this:
using UnityEngine;
using System.Collections;
public class ResetSlingShot : MonoBehaviour {
[SerializeField]
int ResetDelayTime = 5;
[SerializeField]
float dampingRationValue = 100.0f;
bool SlingShot_isTriggered;
SpringJoint2D mySpring;
//-------------------------------------------------------------------
void Start()
{
mySpring.GetComponent<SpringJoint2D>();
}
//-------------------------------------------------------------------
void Update()
{
if (SlingShot_isTriggered == true)
{
StartCoroutine(ResetTimer());
mySpring.dampingRatio = dampingRationValue;
}
}
//-------------------------------------------------------------------
IEnumerator ResetTimer()
{
yield return new WaitForSeconds(ResetDelayTime);
}
}
Answer by bpolaro · Dec 24, 2016 at 11:55 PM
i want to know how to get the spring back after it gets deleted when you set the kinematic
GetComponent().isKinematic = false;
how can i get it back without restarting the scene?