Move camera when clicked on object

This commit is contained in:
Crom (Thibaut CHARLES) 2014-11-01 12:57:46 +01:00
parent f491b04ea5
commit 4518d11ffb
3 changed files with 126 additions and 18 deletions

View File

@ -84,6 +84,7 @@ GameObject:
- 4: {fileID: 212607542}
- 114: {fileID: 212607541}
- 154: {fileID: 212607540}
- 114: {fileID: 212607543}
m_Layer: 0
m_Name: Terrain
m_TagString: Untagged
@ -138,6 +139,19 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
--- !u!114 &212607543
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 212607539}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0100759586662ae43b92a80a83d4b10f, type: 3}
m_Name:
m_EditorClassIdentifier:
destination: {fileID: 717116040}
camCtrl: {fileID: 1859570685}
--- !u!1 &575068630
GameObject:
m_ObjectHideFlags: 0
@ -148,7 +162,7 @@ GameObject:
- 4: {fileID: 575068635}
- 20: {fileID: 575068634}
m_Layer: 0
m_Name: CameraPos1
m_Name: CameraA
m_TagString: CameraPos
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
@ -190,7 +204,7 @@ Transform:
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 575068630}
m_LocalRotation: {x: .313099325, y: .167965993, z: -.0563636683, w: .933048487}
m_LocalPosition: {x: 369.235046, y: 20, z: 342.061523}
m_LocalPosition: {x: 379.450012, y: 11.3999996, z: 342.061523}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
@ -204,7 +218,7 @@ GameObject:
- 4: {fileID: 704469716}
- 20: {fileID: 704469715}
m_Layer: 0
m_Name: CameraPos2
m_Name: CameraB
m_TagString: CameraPos
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
@ -246,7 +260,63 @@ Transform:
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 704469714}
m_LocalRotation: {x: .219791919, y: .685406387, z: -.229999095, w: .654988587}
m_LocalPosition: {x: 351.700012, y: 20, z: 372.700012}
m_LocalPosition: {x: 359.299988, y: 12.5, z: 372.700012}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
--- !u!1 &717116038
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 4
m_Component:
- 4: {fileID: 717116040}
- 20: {fileID: 717116039}
m_Layer: 0
m_Name: CameraTerrain
m_TagString: CameraPos
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 4294967295
m_IsActive: 1
--- !u!20 &717116039
Camera:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 717116038}
m_Enabled: 0
serializedVersion: 2
m_ClearFlags: 1
m_BackGroundColor: {r: .192156866, g: .301960796, b: .474509805, a: .0196078438}
m_NormalizedViewPortRect:
serializedVersion: 2
x: 0
y: 0
width: 1
height: 1
near clip plane: .300000012
far clip plane: 1000
field of view: 60
orthographic: 0
orthographic size: 5
m_Depth: -1
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_RenderingPath: -1
m_TargetTexture: {fileID: 0}
m_HDR: 0
m_OcclusionCulling: 1
--- !u!4 &717116040
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 717116038}
m_LocalRotation: {x: .433290511, y: .375726491, z: -.205278277, w: .793063581}
m_LocalPosition: {x: 368, y: 32.2999992, z: 347.799988}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
@ -261,6 +331,7 @@ GameObject:
- 33: {fileID: 935509385}
- 65: {fileID: 935509384}
- 23: {fileID: 935509383}
- 114: {fileID: 935509387}
m_Layer: 0
m_Name: CubeB
m_TagString: Untagged
@ -319,6 +390,19 @@ Transform:
m_LocalScale: {x: 5, y: 5, z: 5}
m_Children: []
m_Father: {fileID: 0}
--- !u!114 &935509387
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 935509382}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0100759586662ae43b92a80a83d4b10f, type: 3}
m_Name:
m_EditorClassIdentifier:
destination: {fileID: 704469716}
camCtrl: {fileID: 1859570685}
--- !u!1 &1859570684
GameObject:
m_ObjectHideFlags: 0
@ -350,6 +434,8 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 0847dfc9c9ff529478bce7d29ab3f52d, type: 3}
m_Name:
m_EditorClassIdentifier:
targetPos: {x: 0, y: 0, z: 0}
targetRot: {x: 0, y: 0, z: 0, w: 0}
--- !u!81 &1859570686
AudioListener:
m_ObjectHideFlags: 0
@ -484,6 +570,7 @@ GameObject:
- 33: {fileID: 2129107686}
- 65: {fileID: 2129107685}
- 23: {fileID: 2129107684}
- 114: {fileID: 2129107688}
m_Layer: 0
m_Name: CubeA
m_TagString: Untagged
@ -542,3 +629,16 @@ Transform:
m_LocalScale: {x: 5, y: 5, z: 5}
m_Children: []
m_Father: {fileID: 0}
--- !u!114 &2129107688
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 2129107683}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0100759586662ae43b92a80a83d4b10f, type: 3}
m_Name:
m_EditorClassIdentifier:
destination: {fileID: 575068635}
camCtrl: {fileID: 1859570685}

View File

@ -3,29 +3,20 @@ using System.Collections;
public class CameraController : MonoBehaviour {
public Vector3 targetPos;
public Quaternion targetRot;
// Use this for initialization
void Awake () {
targetPos = transform.position;
targetRot = transform.rotation;
cameraPosList = GameObject.FindGameObjectsWithTag("CameraPos");
}
// Update is called once per frame
void Update () {
if(Input.GetKeyDown(KeyCode.F1)){
targetPos = cameraPosList[0].transform.position;
targetRot = cameraPosList[0].transform.rotation;
}
else if(Input.GetKeyDown(KeyCode.F2)){
targetPos = cameraPosList[1].transform.position;
targetRot = cameraPosList[1].transform.rotation;
}
transform.position = Vector3.Lerp(transform.position, targetPos, Time.deltaTime);
transform.rotation = Quaternion.Lerp(transform.rotation, targetRot, Time.deltaTime);
transform.position = Vector3.Lerp(transform.position, targetPos, Time.deltaTime*10);
transform.rotation = Quaternion.Lerp(transform.rotation, targetRot, Time.deltaTime*10);
}
private GameObject[] cameraPosList;
private Vector3 targetPos;
private Quaternion targetRot;
}

View File

@ -0,0 +1,17 @@
//The object must have a collider
using UnityEngine;
using System.Collections;
public class OnClickedMoveCamera : MonoBehaviour {
public Transform destination;
public CameraController camCtrl;
void OnMouseDown()
{
camCtrl.targetPos = destination.position;
camCtrl.targetRot = destination.rotation;
}
}