"moving camera with touch screen unity" Code Answer's
You're definitely familiar with the best coding language C# that developers use to develop their projects and they get all their queries like "moving camera with touch screen unity" answered properly. Developers are finding an appropriate answer about moving camera with touch screen unity related to the C# coding language. By visiting this online portal developers get answers concerning C# codes question like moving camera with touch screen unity. Enter your desired code related query in the search bar and get every piece of information about C# code related question on moving camera with touch screen unity.
moving camera with touch screen unity
using UnityEngine;
using System.Collections;
public class ViewDrag : MonoBehaviour {
Vector3 hit_position = Vector3.zero;
Vector3 current_position = Vector3.zero;
Vector3 camera_position = Vector3.zero;
float z = 0.0f;
// Use this for initialization
void Start () {
}
void Update(){
if(Input.GetMouseButtonDown(0)){
hit_position = Input.mousePosition;
camera_position = transform.position;
}
if(Input.GetMouseButton(0)){
current_position = Input.mousePosition;
LeftMouseDrag();
}
}
void LeftMouseDrag(){
// From the Unity3D docs: "The z position is in world units from the camera." In my case I'm using the y-axis as height
// with my camera facing back down the y-axis. You can ignore this when the camera is orthograhic.
current_position.z = hit_position.z = camera_position.y;
// Get direction of movement. (Note: Don't normalize, the magnitude of change is going to be Vector3.Distance(current_position-hit_position)
// anyways.
Vector3 direction = Camera.main.ScreenToWorldPoint(current_position) - Camera.main.ScreenToWorldPoint(hit_position);
// Invert direction to that terrain appears to move with the mouse.
direction = direction * -1;
Vector3 position = camera_position + direction;
transform.position = position;
}
}
Source: stackoverflow.com
All those coders who are working on the C# based application and are stuck on moving camera with touch screen unity can get a collection of related answers to their query. Programmers need to enter their query on moving camera with touch screen unity related to C# code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about moving camera with touch screen unity for the programmers working on C# code while coding their module. Coders are also allowed to rectify already present answers of moving camera with touch screen unity while working on the C# language code. Developers can add up suggestions if they deem fit any other answer relating to "moving camera with touch screen unity". Visit this developer's friendly online web community, CodeProZone, and get your queries like moving camera with touch screen unity resolved professionally and stay updated to the latest C# updates.