Search Unity

Question Easy Code Question

Discussion in 'Editor & General Support' started by geronimoandressantos, Jun 8, 2020.

  1. geronimoandressantos

    geronimoandressantos

    Joined:
    Jun 7, 2020
    Posts:
    12
    Hey guys so i made this code and it works perfectly on my computer, its a scene changer

    when i click with my mouse it changes the scene but i dont know how to make it so when i touch my screen on my android the scene changes

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.SceneManagement;
    5.  
    6. public class LoadScene : MonoBehaviour
    7. {
    8.     public string scene;
    9.  
    10.     private void OnMouseDown()
    11.     {
    12.         SceneManager.LoadScene(scene);
    13.     }
    14. }
    15.  
     
  2. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,195
  3. geronimoandressantos

    geronimoandressantos

    Joined:
    Jun 7, 2020
    Posts:
    12
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.SceneManagement;
    5. public class LoadScene : MonoBehaviour
    6. {
    7.     public string scene;
    8.       if (Input.touchCount > 0)
    9.     {
    10.         SceneManager.LoadScene(scene);
    11.     }
    12. }

    like this ?
     
  4. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    Close but no cigar.
    You would need to put the code that checks for the touch inside the Update function (like on the docu page you quoted).