Added stretch and snap to slingshot

This commit is contained in:
Trianta
2024-02-22 01:23:52 -06:00
parent 1794d081dd
commit 5e9e2d7790
5 changed files with 160 additions and 0 deletions
+7
View File
@@ -8,6 +8,8 @@ public class Slingshot : MonoBehaviour
[Header("Set in Inspector")]
public GameObject prefabProjectile;
public float velocityMult = 8f;
public AudioClip stretchBandSound;
public AudioClip snapBandSound;
// fields set dynamically
[Header("Set Dynamically")]
public GameObject launchPoint;
@@ -15,6 +17,8 @@ public class Slingshot : MonoBehaviour
public GameObject projectile;
public bool aimingMode;
private Rigidbody projectileRigidbody;
public AudioSource audioSource;
public float volume = 0.5f;
static public Vector3 LAUNCH_POS {
get {
if (s == null) return Vector3.zero;
@@ -48,6 +52,8 @@ public class Slingshot : MonoBehaviour
// Set it to isKinematic for now
projectileRigidbody = projectile.GetComponent<Rigidbody>();
projectileRigidbody.isKinematic = true;
audioSource = GetComponent<AudioSource>();
audioSource.PlayOneShot(stretchBandSound, volume);
}
void Update() {
// If Slingshot is not in aimingMode, don't run this code
@@ -81,6 +87,7 @@ public class Slingshot : MonoBehaviour
MissionDemolition.ShotFired();
ProjectileLine.s.poi = projectile;
slingshotBand.SetPosition(1, new Vector3(0,0,0));
audioSource.PlayOneShot(snapBandSound, volume);
}
}
}