Add instantiate on mouse pos
This commit is contained in:
parent
4c3ed46236
commit
f7a5778c95
|
@ -17,14 +17,21 @@ namespace AsteroidGame.Handlers
|
||||||
|
|
||||||
private void OnClick(InputValue value)
|
private void OnClick(InputValue value)
|
||||||
{
|
{
|
||||||
var tempVec = new Vector3(Mouse.current.position.ReadValue().x, Mouse.current.position.ReadValue().y, -_camera.transform.position.z);
|
Vector3 tempVec = new Vector3();
|
||||||
|
Plane plane = new Plane(Vector3.up, Vector3.zero);
|
||||||
|
Ray ray = Camera.main.ScreenPointToRay(Mouse.current.position.ReadValue());
|
||||||
|
if (plane.Raycast(ray, out float distance))
|
||||||
|
{
|
||||||
|
tempVec = ray.GetPoint(distance);
|
||||||
|
}
|
||||||
|
//var tempVec = new Vector3(Mouse.current.position.ReadValue().x, Mouse.current.position.ReadValue().y, -_camera.transform.position.z);
|
||||||
// var point = _camera.ScreenToWorldPoint(tempVec);
|
// var point = _camera.ScreenToWorldPoint(tempVec);
|
||||||
// var ray = _camera.ScreenPointToRay(tempVec);
|
// var ray = _camera.ScreenPointToRay(tempVec);
|
||||||
// print($"Mouse:{Mouse.current.position.ReadValue()} world:{point}");
|
// print($"Mouse:{Mouse.current.position.ReadValue()} world:{point}");
|
||||||
// if (!Physics.Raycast(ray, out var hit)) return;
|
// if (!Physics.Raycast(ray, out var hit)) return;
|
||||||
// var pos = hit.transform.position;
|
// var pos = hit.transform.position;
|
||||||
// print($"{hit.transform.name} was hit! world:{pos}");
|
// print($"{hit.transform.name} was hit! world:{pos}");
|
||||||
Instantiate(buildings[buildingSelector], _camera.ScreenToWorldPoint(tempVec), Quaternion.identity, transform);
|
Instantiate(buildings[buildingSelector], tempVec, Quaternion.identity, transform);
|
||||||
//var spawnPoint = new Vector3(1, 1, 0);
|
//var spawnPoint = new Vector3(1, 1, 0);
|
||||||
//Instantiate(buildings[buildingSelector], spawnPoint, Quaternion.identity, transform);
|
//Instantiate(buildings[buildingSelector], spawnPoint, Quaternion.identity, transform);
|
||||||
|
|
||||||
|
|
|
@ -363,4 +363,4 @@ MonoBehaviour:
|
||||||
zoomSpeed: 2
|
zoomSpeed: 2
|
||||||
maxRotationSpeed: 1
|
maxRotationSpeed: 1
|
||||||
edgeTolerance: 0.05
|
edgeTolerance: 0.05
|
||||||
useScreenEdge: 1
|
useScreenEdge: 0
|
||||||
|
|
|
@ -237,7 +237,7 @@ Transform:
|
||||||
- {fileID: 436649171}
|
- {fileID: 436649171}
|
||||||
- {fileID: 1158682046}
|
- {fileID: 1158682046}
|
||||||
m_Father: {fileID: 0}
|
m_Father: {fileID: 0}
|
||||||
m_RootOrder: 4
|
m_RootOrder: 3
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
--- !u!4 &436649171 stripped
|
--- !u!4 &436649171 stripped
|
||||||
Transform:
|
Transform:
|
||||||
|
@ -468,104 +468,6 @@ Camera:
|
||||||
m_CorrespondingSourceObject: {fileID: 8083988910449603034, guid: c2b4fe01faa847f4b976b5539477e1ec, type: 3}
|
m_CorrespondingSourceObject: {fileID: 8083988910449603034, guid: c2b4fe01faa847f4b976b5539477e1ec, type: 3}
|
||||||
m_PrefabInstance: {fileID: 1191794244}
|
m_PrefabInstance: {fileID: 1191794244}
|
||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
--- !u!1 &1968648952
|
|
||||||
GameObject:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
serializedVersion: 6
|
|
||||||
m_Component:
|
|
||||||
- component: {fileID: 1968648956}
|
|
||||||
- component: {fileID: 1968648955}
|
|
||||||
- component: {fileID: 1968648954}
|
|
||||||
- component: {fileID: 1968648953}
|
|
||||||
m_Layer: 0
|
|
||||||
m_Name: Ecliptic
|
|
||||||
m_TagString: Untagged
|
|
||||||
m_Icon: {fileID: 0}
|
|
||||||
m_NavMeshLayer: 0
|
|
||||||
m_StaticEditorFlags: 0
|
|
||||||
m_IsActive: 1
|
|
||||||
--- !u!64 &1968648953
|
|
||||||
MeshCollider:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
m_GameObject: {fileID: 1968648952}
|
|
||||||
m_Material: {fileID: 0}
|
|
||||||
m_IsTrigger: 0
|
|
||||||
m_Enabled: 1
|
|
||||||
serializedVersion: 4
|
|
||||||
m_Convex: 0
|
|
||||||
m_CookingOptions: 30
|
|
||||||
m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0}
|
|
||||||
--- !u!23 &1968648954
|
|
||||||
MeshRenderer:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
m_GameObject: {fileID: 1968648952}
|
|
||||||
m_Enabled: 1
|
|
||||||
m_CastShadows: 1
|
|
||||||
m_ReceiveShadows: 1
|
|
||||||
m_DynamicOccludee: 1
|
|
||||||
m_StaticShadowCaster: 0
|
|
||||||
m_MotionVectors: 1
|
|
||||||
m_LightProbeUsage: 1
|
|
||||||
m_ReflectionProbeUsage: 1
|
|
||||||
m_RayTracingMode: 2
|
|
||||||
m_RayTraceProcedural: 0
|
|
||||||
m_RenderingLayerMask: 1
|
|
||||||
m_RendererPriority: 0
|
|
||||||
m_Materials:
|
|
||||||
- {fileID: 2100000, guid: 7ab977a21c92388468ee65ad1c0e5a78, type: 2}
|
|
||||||
m_StaticBatchInfo:
|
|
||||||
firstSubMesh: 0
|
|
||||||
subMeshCount: 0
|
|
||||||
m_StaticBatchRoot: {fileID: 0}
|
|
||||||
m_ProbeAnchor: {fileID: 0}
|
|
||||||
m_LightProbeVolumeOverride: {fileID: 0}
|
|
||||||
m_ScaleInLightmap: 1
|
|
||||||
m_ReceiveGI: 1
|
|
||||||
m_PreserveUVs: 0
|
|
||||||
m_IgnoreNormalsForChartDetection: 0
|
|
||||||
m_ImportantGI: 0
|
|
||||||
m_StitchLightmapSeams: 1
|
|
||||||
m_SelectedEditorRenderState: 3
|
|
||||||
m_MinimumChartSize: 4
|
|
||||||
m_AutoUVMaxDistance: 0.5
|
|
||||||
m_AutoUVMaxAngle: 89
|
|
||||||
m_LightmapParameters: {fileID: 0}
|
|
||||||
m_SortingLayerID: 0
|
|
||||||
m_SortingLayer: 0
|
|
||||||
m_SortingOrder: 0
|
|
||||||
m_AdditionalVertexStreams: {fileID: 0}
|
|
||||||
--- !u!33 &1968648955
|
|
||||||
MeshFilter:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
m_GameObject: {fileID: 1968648952}
|
|
||||||
m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0}
|
|
||||||
--- !u!4 &1968648956
|
|
||||||
Transform:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
m_GameObject: {fileID: 1968648952}
|
|
||||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
|
||||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
|
||||||
m_LocalScale: {x: 1000, y: 1000, z: 1000}
|
|
||||||
m_ConstrainProportionsScale: 1
|
|
||||||
m_Children: []
|
|
||||||
m_Father: {fileID: 0}
|
|
||||||
m_RootOrder: 3
|
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
|
||||||
--- !u!1 &2047541735
|
--- !u!1 &2047541735
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|
|
@ -48,6 +48,7 @@ namespace AsteroidGame
|
||||||
private float zoomHeight;
|
private float zoomHeight;
|
||||||
private Vector3 horizontalVelocity;
|
private Vector3 horizontalVelocity;
|
||||||
private Vector3 lastPosition;
|
private Vector3 lastPosition;
|
||||||
|
private Plane cameraPlane;
|
||||||
|
|
||||||
Vector3 startDrag;
|
Vector3 startDrag;
|
||||||
|
|
||||||
|
@ -59,6 +60,7 @@ namespace AsteroidGame
|
||||||
|
|
||||||
private void OnEnable()
|
private void OnEnable()
|
||||||
{
|
{
|
||||||
|
cameraPlane = new Plane(Vector3.up, Vector3.zero);
|
||||||
zoomHeight = cameraTransform.localPosition.y;
|
zoomHeight = cameraTransform.localPosition.y;
|
||||||
cameraTransform.LookAt(this.transform);
|
cameraTransform.LookAt(this.transform);
|
||||||
lastPosition = this.transform.position;
|
lastPosition = this.transform.position;
|
||||||
|
@ -194,9 +196,9 @@ namespace AsteroidGame
|
||||||
{
|
{
|
||||||
if (!Mouse.current.rightButton.isPressed) { return; }
|
if (!Mouse.current.rightButton.isPressed) { return; }
|
||||||
|
|
||||||
Plane plane = new Plane(Vector3.up, Vector3.zero);
|
|
||||||
Ray ray = Camera.main.ScreenPointToRay(Mouse.current.position.ReadValue());
|
Ray ray = Camera.main.ScreenPointToRay(Mouse.current.position.ReadValue());
|
||||||
if (plane.Raycast(ray,out float distance))
|
if (cameraPlane.Raycast(ray,out float distance))
|
||||||
{
|
{
|
||||||
if (Mouse.current.rightButton.wasPressedThisFrame)
|
if (Mouse.current.rightButton.wasPressedThisFrame)
|
||||||
startDrag = ray.GetPoint(distance);
|
startDrag = ray.GetPoint(distance);
|
||||||
|
|
Loading…
Reference in New Issue