Hello everybody I create two scripts and they should start cutscene and end it. Also with some turn off component so player cant move while cutscene, but I am not so experienced with Scripting, and I made a few mistakes because this script doesn’t work at all.
Here is the first Script what do Raycasting
RaycastHit cellPhone;
Ray phoneRay = GetComponent<Camera>().ViewportPointToRay(new Vector3(0.5f, 0.5f, 0f));
if (Physics.Raycast(phoneRay, out cellPhone, PhoneRayDistance))
{
if (hit.transform.gameObject.tag == "Phone")
{
if (Input.GetButtonDown("actButton"))
{
GetComponent<phoneAnimationScript>().CutSceneStart();
Debug.Log("RayHitPhone");
}
Debug.Log("RayHitPhone");
}
}
}
And a second one what should turn off components and start an animation
public class phoneAnimationScript : MonoBehaviour {
private Animator cellPhoneAnimatorCtrl;
public Animation cellPhoneAnimation;
private AnimatorStateInfo BaseLayer;
static int answerPhoneAct = Animator.StringToHash("Base Layer.phoneAnswerAnim");
private AnimatorStateInfo currentBaseState;
public CharacterMotor MovementScript;
public MouseLook CameraMovementScript;
void Start () {
cellPhoneAnimatorCtrl = GetComponent<Animator>();
cellPhoneAnimation = GetComponent<Animation>();
MovementScript = GetComponent<CharacterMotor>();
CameraMovementScript = GetComponent<MouseLook>();
}
public IEnumerator CutSceneStart()
{
PhoneAnimationStart();
CharacterAnimationStart();
yield return new WaitForSeconds(5);
TurnOnEverything();
}
public void PhoneAnimationStart()
{
cellPhoneAnimation.Play("take a phone");
}
public void CharacterAnimationStart()
{
MovementScript.enabled = false;
CameraMovementScript.enabled = false;
cellPhoneAnimatorCtrl.SetBool("phoneAnswer", true);
}
public void TurnOnEverything()
{
MovementScript.enabled = true;
CameraMovementScript.enabled = true;
}
}
Yeah it give some progress now Animation from phone starts, but character animation is not.
I tried to add created a reference for character too, but it gives me an error
public phoneAnimationScript myphoneAnimationScript;
public phoneAnimationScript myCharacterAnimationScript;
if (Input.GetButtonDown("actButton"))
{
phoneAnimationScript pas = GetComponent<phoneAnimationScript>();
StartCoroutine(myphoneAnimationScript.CutSceneStart());
StartCoroutine(myCharacterAnimationScript.CutSceneStart());
}
(MissingComponentException: There is no ‘Animation’ attached to the “Player” game object, but a script is trying to access it.
You probably need to add a Animation to the game object “Player”. Or your script needs to check if the component is attached before using it.)
My character is controlled by a AnimationController, Should I add separate Animation component for this action?
Animation is the legacy animation system, Animator is the new mecanim system. If you’re using an AnimationController, you should be using Animator and not Animation.