Switch between Cameras on Android.

Dear members.

Pleas can some one help me whit make this script triger on touch of android and not on key down?

I need simple on touch swich camera that worck on 3d colider by trigering whit touch.

  • public Transform Player;
  • public Camera FirstPersonCam, ThirdPersonCam;
  • public KeyCode TKey;
  • public bool camSwitch = false;
  • void Update()
  • {
  • if (Input.GetKeyDown(TKey))
  • {
  • camSwitch = !camSwitch;
  • FirstPersonCam.gameObject.SetActive(camSwitch);
  • ThirdPersonCam.gameObject.SetActive(!camSwitch);
  • }
  • }
  • }

Tnx to all four your time and solution.
Best regards
Dubravko.

Please use code tags to surround your code, as mentioned in Using code tags properly

It makes it far easier for other programmers to read, and use your code snippet.

I would do:

if (Input.touchCount > 0)
        {
           // do something on touch
camSwitch = !camSwitch;
FirstPersonCam.gameObject.SetActive(camSwitch);
ThirdPersonCam.gameObject.SetActive(!camSwitch);
        }

But if you require better touch handling, something like: Simple swipe and tap mobile input

Dear sir i make it worck by implement if… touchCount… like you say buth got problem.
Its glich and shake when swich by touch do i miss some ?? to make it smoth cam svich ?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class camsvich : MonoBehaviour
{

public Camera FirstPersonCam, ThirdPersonCam;
public KeyCode TKey;
public bool camSwitch = false;
void Update()
{
if (Input.touchCount > 0)
{
camSwitch = !camSwitch;
FirstPersonCam.gameObject.SetActive(camSwitch);
ThirdPersonCam.gameObject.SetActive(!camSwitch);
}
}
}

Here is gif video of problem please help if you can.
https://ibb.co/fNV7hGD