質問編集履歴
1
スクリプトを更新しました、
title
CHANGED
File without changes
|
body
CHANGED
@@ -8,39 +8,41 @@
|
|
8
8
|
using System.Collections.Generic;
|
9
9
|
using UnityEngine;
|
10
10
|
|
11
|
-
public class
|
11
|
+
public class ray2 : MonoBehaviour
|
12
12
|
{
|
13
|
+
//public GameObject targetObject;
|
14
|
+
|
13
|
-
|
15
|
+
Vector3 m_ZAixs;
|
16
|
+
public Rigidbody m_Rigidbody;
|
14
|
-
|
17
|
+
public GameObject Light;
|
18
|
+
// Use this for initialization
|
15
19
|
void Start()
|
16
20
|
{
|
21
|
+
m_Rigidbody = Light.GetComponent<Rigidbody>();
|
22
|
+
m_Rigidbody.constraints = RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezePositionZ;
|
23
|
+
|
24
|
+
// Update is called once per frame
|
17
25
|
}
|
18
|
-
// Update is called once per frame
|
19
26
|
void Update()
|
20
27
|
{
|
21
|
-
Vector2 touchScreenPosition = Input.mousePosition;
|
22
|
-
|
23
|
-
touchScreenPosition.x = Mathf.Clamp(touchScreenPosition.x, 0.0f, Screen.width);
|
24
|
-
touchScreenPosition.y = Mathf.Clamp(touchScreenPosition.y, 0.0f, Screen.height);
|
25
|
-
|
26
|
-
Camera gameCamera = Camera.main;
|
27
|
-
Ray touchPointToRay = gameCamera.ScreenPointToRay(touchScreenPosition);
|
28
|
-
|
29
|
-
RaycastHit hitInfo = new RaycastHit();
|
30
|
-
if (
|
28
|
+
if (Input.GetMouseButtonDown(0))
|
31
29
|
{
|
30
|
+
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
31
|
+
RaycastHit hit;
|
32
|
+
if (Physics.Raycast(ray, out hit, Mathf.Infinity))
|
33
|
+
{
|
34
|
+
GameObject t = GameObject.Find("SpotLightWhite 1 1(Clone)");
|
35
|
+
var targetPos = new Vector3(hit.point.x, hit.point.y, hit.point.z);
|
32
|
-
|
36
|
+
t.transform.position = targetPos;
|
37
|
+
}
|
33
38
|
}
|
34
|
-
|
35
|
-
Debug.DrawRay(touchPointToRay.origin, touchPointToRay.direction * 1000.0f);
|
36
|
-
|
37
39
|
if (Input.GetKeyDown(KeyCode.S))
|
38
40
|
{
|
39
|
-
GetComponent<
|
41
|
+
//Light.GetComponent<Rigidbody>();
|
42
|
+
//m_Rigidbody.constraints = RigidbodyConstraints.FreezeAll;
|
40
43
|
}
|
41
44
|
}
|
42
45
|
}
|
43
|
-
|
44
46
|
### 試したこと
|
45
47
|
オブジェクトにRigidbodyを付与して、Frezzeしても動きます。
|
46
48
|
Rayで動かすScriptを無効化してもダメでした。
|