How can I rotate camera of Player with touch the screen ?

PLEASE ADD SCRIPT WITH C# . Thank you so much for help :slight_smile:

This does not give us anywhere near enough information to be able to help you if we wanted to.

If this is all there is to your question, search for a tutorial instead.

1 Like

Sorry I’m new in Unity …My idea is gun shooting and i want give it 360 degree rotation up ,down, left , right but only when swipe the screen

I attached script to the main camera to follow player

using UnityEngine;
using System.Collections;

public class Cameracontroller : MonoBehaviour {

public GameObject Player;

private Vector3 offset;

void Start ()
{
offset = transform.position - Player.transform.position;

}

void LateUpdate ()
{
transform.position = Player.transform.position + offset;

}
}

I found this script to rotate main camera of player but the issue i want the camera stay focus on the gun of player when i try at the same time rotate up , down , left , right

using UnityEngine;
using System.Collections;

public class MoveCamera : MonoBehaviour
{
//
// VARIABLES
//

public float turnSpeed = 4.0f; // Speed of camera turning when mouse moves in along an axis
public float panSpeed = 4.0f; // Speed of the camera when being panned
public float zoomSpeed = 4.0f; // Speed of the camera going back and forth

private Vector3 mouseOrigin; // Position of cursor when mouse dragging starts
private bool isPanning; // Is the camera being panned?
private bool isRotating; // Is the camera being rotated?
private bool isZooming; // Is the camera zooming?

//
// UPDATE
//

void Update ()
{
// Get the left mouse button
if(Input.GetMouseButtonDown(0))
{
// Get mouse origin
mouseOrigin = Input.mousePosition;
isRotating = true;
}

// Get the right mouse button
if(Input.GetMouseButtonDown(1))
{
// Get mouse origin
mouseOrigin = Input.mousePosition;
isPanning = true;
}

// Get the middle mouse button
if(Input.GetMouseButtonDown(2))
{
// Get mouse origin
mouseOrigin = Input.mousePosition;
isZooming = true;
}

// Disable movements on button release
if (!Input.GetMouseButton(0)) isRotating=false;
if (!Input.GetMouseButton(1)) isPanning=false;
if (!Input.GetMouseButton(2)) isZooming=false;

// Rotate camera along X and Y axis
if (isRotating)
{
Vector3 pos = Camera.main.ScreenToViewportPoint(Input.mousePosition - mouseOrigin);

transform.RotateAround(transform.position, transform.right, -pos.y * turnSpeed);
transform.RotateAround(transform.position, Vector3.up, pos.x * turnSpeed);
}

// Move the camera on it’s XY plane
if (isPanning)
{
Vector3 pos = Camera.main.ScreenToViewportPoint(Input.mousePosition - mouseOrigin);

Vector3 move = new Vector3(pos.x * panSpeed, pos.y * panSpeed, 0);
transform.Translate(move, Space.Self);
}

// Move the camera linearly along Z axis
if (isZooming)
{
Vector3 pos = Camera.main.ScreenToViewportPoint(Input.mousePosition - mouseOrigin);

Vector3 move = pos.y * zoomSpeed * transform.forward;
transform.Translate(move, Space.World);
}
}
}