-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathController.cs
113 lines (93 loc) · 2.68 KB
/
Controller.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//using AdvancedInspector;
public class Controller : MonoBehaviour {
bool direction = true;
bool sphere = true;
[SerializeField]
GameObject sphereParent;
[SerializeField]
GameObject sphereChild;
Rigidbody rbParent;
Rigidbody rbChild;
[SerializeField]
MeshRenderer cylinderParent;
[SerializeField]
MeshRenderer cylinderChild;
[SerializeField]
GameObject panel;
// Use this for initialization
void Start () {
rbParent = sphereParent.GetComponent<Rigidbody>();
rbChild = sphereChild.GetComponent<Rigidbody>();
ChangeDirection();
sphereChild.layer = 0; //Default
rbChild.mass = 1.0f;
cylinderChild.enabled = true;
sphereParent.layer = 8; //NoCollide
rbParent.mass = 0.01f;
cylinderParent.enabled = false;
}
// Update is called once per frame
void Update ()
{
if (sphereParent.transform.position.y < -20)
{
rbChild.isKinematic = true;
rbParent.isKinematic = true;
panel.SetActive(true);
}
if (Input.GetMouseButtonUp(0))
{
//print("左ボタンが押されている");
ChangeSphere();
}
}
//[Inspect]
void ChangeDirection()
{
if (direction)
{
Vector3 newGravity = new Vector3(3.0f, -9.8f);
Physics.gravity = newGravity;
}
else
{
Vector3 newGravity = new Vector3(-3.0f, -9.8f);
Physics.gravity = newGravity;
}
direction = !direction;
}
//[Inspect]
void ChangeSphere()
{
if (sphere)
{
sphereChild.layer = 0; //Default
rbChild.mass = 1.0f;
cylinderChild.enabled = true;
//rbChild.isKinematic = false;
//rbChild.useGravity = true;
sphereParent.layer = 8; //NoCollide
rbParent.mass = 0.01f;
cylinderParent.enabled = false;
//rbParent.isKinematic = true;
//rbParent.useGravity = false;
}
else
{
sphereParent.layer = 0; //Default
rbParent.mass = 1.0f;
cylinderParent.enabled = true;
//rbParent.isKinematic = false;
//rbParent.useGravity = true;
sphereChild.layer = 8; //NoCollide
rbChild.mass = 0.01f;
cylinderChild.enabled = false;
//rbChild.isKinematic = true;
//rbChild.useGravity = false;
}
sphere = !sphere;
}
}