Post by freakystudios on Apr 24, 2020 18:26:31 GMT
Can anyone make Car enter exit with animation I have made a script but in the script when the player enters the car player position and rotation changes and he directly sits inside the car and the animation driving gets activated can anyone help me so that the player can perform animation of opeining door and closes the door and same goes for the exit.Since i am making it for mobile...
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class animationcar : MonoBehaviour
{
public GameObject ThePlayer;
public GameObject ThePlayerCam;
public GameObject TheCar;
public GameObject CarCanvas;
public GameObject CarCam;
public GameObject EnterButton;
public GameObject carsitposition;
public GameObject ExitTrigger;
public string script;
public CharacterComponents characterComponents;
/* public Rigidbody myRigidbody;
public Collider myCollider;
public ThirdPersonCharacter myThirdPersonCharacter; */
[System.Serializable]
public class CharacterComponents
{
public Rigidbody myRigidbody;
public Collider myCollider;
}
public void ComponentsStatus(bool active)
{
characterComponents.myRigidbody.isKinematic = !active;
characterComponents.myCollider.enabled = active;
}
void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
EnterButton.gameObject.SetActive(true);
}
}
void OnTriggerExit(Collider other)
{
if (other.CompareTag("Player"))
{
EnterButton.gameObject.SetActive(false);
}
}
public void EnterSystem()
{
(ThePlayer.GetComponent(script) as MonoBehaviour).enabled = false;
CarCam.SetActive(true);
CarCanvas.SetActive(true);
ThePlayerCam.SetActive(false);
ComponentsStatus(false);
ThePlayer.transform.position = carsitposition.transform.position;
ThePlayer.transform.rotation = carsitposition.transform.rotation;
ThePlayer.transform.parent = TheCar.transform;
}
public void ExitSystem()
{
CarCam.SetActive(false);
CarCanvas.SetActive(false);
ThePlayerCam.SetActive(true);
ThePlayer.transform.position = ExitTrigger.transform.position;
ThePlayer.transform.rotation = ExitTrigger.transform.rotation;
ThePlayer.transform.parent = null;
ComponentsStatus(true);
(ThePlayer.GetComponent(script) as MonoBehaviour).enabled = true;
}
}