Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

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,215
  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).