- Home /
Question by
Manacraft05 · Mar 28, 2019 at 10:26 PM ·
animationcameraplayervariablekeyboard input
Camera switch | issue
the player script :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class switchdimension : MonoBehaviour {
public bool IsIn2D = false;
public Camera Cam3d;
public Camera Cam2d;
public Animator anim;
public Animator anim2;
void FixedUpdate()
{
if (Input.GetButtonDown("Switch Dimension"))
{
IsIn2D = !IsIn2D; //invert the state
StartCoroutine(Animation());
}
}
IEnumerator Animation()
{
yield return new WaitForSeconds(0.5f); //wait for the animation
Cam2d.enabled = IsIn2D; //switch cameras ( here's the bug )
Cam3d.enabled = !IsIn2D;
}
}
sometime the animation plays ( it's in a other script ) but the IsFlat variable don't change and the cameras don't switch.
Animation script :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraAnim : MonoBehaviour
{
public Animator anim;
public string name;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetButtonUp("Switch Dimension"))
{
anim.Play(name);
}
}
}
Comment