Hi all,
In the morning i asked one question
http://answers.unity3d.com/questions/442791/how-will-my-camera-to-move-in-the-direction-of-dra.html
but i didn’t get any replies. ok For that. I tried like this.
using UnityEngine;
using System.Collections;
public class ShowObject : MonoBehaviour {
public Transform myObject;
public Camera myCamera;
bool check = true;
Vector3 positionOne,positionTwo;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(Input.GetMouseButtonDown(0) ){
//Debug.Log("Drag");
check = true;
positionOne = Input.mousePosition;
}
if(Input.GetMouseButton(0)) {
if(check) {
if(positionOne != Input.mousePosition) {
if(positionOne.x < Input.mousePosition.x ) {
myCamera.transform.position = new Vector3 (myCamera.transform.position.x+(-positionOne.x + Input.mousePosition.x)*0.01f,myCamera.transform.position.y,myCamera.transform.position.z);
}
else {
myCamera.transform.position = new Vector3 (myCamera.transform.position.x+(-positionOne.x + Input.mousePosition.x)*0.01f,myCamera.transform.position.y,myCamera.transform.position.z);
}
if(positionOne.y < Input.mousePosition.y) {
myCamera.transform.position = new Vector3 (myCamera.transform.position.x,myCamera.transform.position.y+(-positionOne.y + Input.mousePosition.y)*0.01f,myCamera.transform.position.z);
}
else {
myCamera.transform.position = new Vector3 (myCamera.transform.position.x,myCamera.transform.position.y+(-positionOne.y + Input.mousePosition.y)*0.01f,myCamera.transform.position.z);
}
myCamera.transform.LookAt(myObject);
positionTwo = Input.mousePosition;
positionOne = positionTwo;
}
}
}
}
}
I created an empty game object and i added this code. in the inspector view also i added all the things.
My problem is when i am dragging first time the object is not shown correctly. my main camera totally changes some 10 points in the x,y,z directions. In the second time onwards it is prefect.
in my observation if i drag , I object is going back looks like but really camera is going back.
can i get any help. please help me
thanks
Navadeep
Thanks for your reply mr Robertbu, still i am getting same output after i replace with your code also.I have an object which i need to show this view 360 degrees in all directions(i.e both in horizontal and vertical directions). Actually in this case when i am attempt to drag the mouse to left most and right most then camera view should be focus to object and will shows upto 360 degrees accordingly and also in top most and bottom vice versa, so could you please let me know how to implement the code for this issue and that will be great help ful to me Thanks in advance.
– navadeep2011