Skip to content

Instantly share code, notes, and snippets.

@kleberandrade
Created September 7, 2019 00:45
Show Gist options
  • Save kleberandrade/7c274068ae80e0e17b3589124c925632 to your computer and use it in GitHub Desktop.
Save kleberandrade/7c274068ae80e0e17b3589124c925632 to your computer and use it in GitHub Desktop.
using UnityEngine;
public class Drawbridge : MonoBehaviour
{
public float[] m_Targets = { 90.0f, 0.0f };
private int m_Index = 0;
private HingeJoint m_Joint;
private void Awake()
{
m_Joint = GetComponent<HingeJoint>();
}
private void Update()
{
if (Input.GetButtonDown("Fire1"))
{
JointSpring spring = m_Joint.spring;
m_Index = ++m_Index % m_Targets.Length;
spring.targetPosition = m_Targets[m_Index];
m_Joint.spring = spring;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment