Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Cannot Convert string to bool error

Discussion in 'Scripting' started by GooberFishey, Oct 7, 2022.

  1. GooberFishey

    GooberFishey

    Joined:
    Aug 11, 2022
    Posts:
    3
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class CamSwitcher : MonoBehaviour
    6.  
    7. {
    8.     public GameObject cam1;
    9.     public GameObject cam2;
    10.    
    11.      // Start is called before the first frame update
    12.     void Start()
    13.     {
    14.        
    15.     }
    16.  
    17.     // Update is called once per frame
    18.     void Update()
    19.     {
    20.        if (Input.GetButtonDown("v"))
    21.        {
    22.           //setting cam1 active
    23.           cam1.SetActive("True");
    24.           cam2.SetActive("False");
    25.        }
    26.        if (Input.GetButtonDown("c"))
    27.        {
    28.         //setting cam2 active
    29.         cam1.SetActive("False");
    30.         cam2.SetActive("True");
    31.        }
    32.  
    33.  
    34.     }
    35. }
    36.  
    It says cannot convert string to bool... what am i doing wrong here?
     
  2. kei233

    kei233

    Joined:
    Dec 16, 2019
    Posts:
    49
    cam1.SetActive(true);
    no ""
     
    Kiwasi and spiney199 like this.
  3. GooberFishey

    GooberFishey

    Joined:
    Aug 11, 2022
    Posts:
    3
    Thanks so much!
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,951
    Just want to call out that I see you playing with camera stuff... Unity offers a Cinemachine package which is pretty awesome in all that it does... might be worth your time to investigate.

    Cinemachine can be installed from the Unity Package Manager.

    There's even a dedicated forum: https://forum.unity.com/forums/cinemachine.136/