You are on page 1of 2

public class ChairMoovement : MonoBehaviour

{
// At least player or chair has rigodbody so as to make collision happens

//Remove rigidbody(5) to make sure the chair remains static even in collisions
public Rigidbody chairRB;

[SerializeField]
public GameObject player;
public float speed = 1;
public bool isOnHand;
public Vector3 offset;
public bool isGrabbale;

// Start is called before the first frame update


void Start()
{
chairRB = GetComponent<Rigidbody>();
isOnHand = false;
offset = Vector3.up * 2 ;
chairRB.isKinematic = false;

private void Update()


{
if (isGrabbale == true)
{
if (Input.GetKeyDown(KeyCode.Alpha1))
{
chairRB.isKinematic = true;
transform.parent = player.transform;
transform.position = player.transform.position + player.transform.forward * 8 +
offset;
isOnHand = true;
}
//else if (Input.GetKeyDown(KeyCode.Alpha2))
//{
// chairRB.AddForce(player.transform.position * speed * Time.deltaTime,
ForceMode.Force);
//}
}

if (isOnHand == true)
{
if (Input.GetKeyDown(KeyCode.Alpha3))
{
chairRB.isKinematic = false;
transform.parent = null;
isOnHand = false;
//if (transform.parent = null)
//{
// isOnHand = false;
//}
}
}

{
Debug.Log("Player collides with a chair!");
player = collision.gameObject;
isGrabbale = true;
}

private void OnCollisionExit(Collision collision)


{
isGrabbale = false;
}
}

You might also like