2022-10-27 12:32:06 +08:00
|
|
|
|
using SHADE;
|
|
|
|
|
using System;
|
|
|
|
|
public class PhysicsTest : Script
|
|
|
|
|
{
|
|
|
|
|
[SerializeField]
|
|
|
|
|
[Tooltip("Force to apply when pressing Space.")]
|
2022-10-27 17:51:30 +08:00
|
|
|
|
private Vector3 Force = new Vector3(0.0f, 200.0f, 0.0f);
|
|
|
|
|
private Transform Transform;
|
2022-10-27 12:32:06 +08:00
|
|
|
|
private RigidBody RigidBody;
|
|
|
|
|
private Collider Collider;
|
|
|
|
|
public PhysicsTest(GameObject gameObj) : base(gameObj) { }
|
|
|
|
|
|
|
|
|
|
protected override void awake()
|
|
|
|
|
{
|
2022-10-27 17:51:30 +08:00
|
|
|
|
Transform = GetComponent<Transform>();
|
|
|
|
|
if (Transform == null)
|
|
|
|
|
{
|
|
|
|
|
Debug.LogError("Transform is NULL!");
|
|
|
|
|
}
|
2022-10-27 12:32:06 +08:00
|
|
|
|
RigidBody = GetComponent<RigidBody>();
|
|
|
|
|
if (RigidBody == null)
|
|
|
|
|
{
|
|
|
|
|
Debug.LogError("RigidBody is NULL!");
|
|
|
|
|
}
|
|
|
|
|
Collider = GetComponent<Collider>();
|
|
|
|
|
if (Collider == null)
|
|
|
|
|
{
|
|
|
|
|
Debug.LogError("Collider is NULL!");
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-30 02:37:58 +08:00
|
|
|
|
var subColider = Collider.CollisionShapeCount;
|
2022-10-27 12:32:06 +08:00
|
|
|
|
Debug.Log($"There are {subColider} colliders.");
|
|
|
|
|
}
|
|
|
|
|
protected override void update()
|
|
|
|
|
{
|
|
|
|
|
if (Input.GetKeyUp(Input.KeyCode.Space))
|
|
|
|
|
{
|
|
|
|
|
RigidBody.AddForce(Force);
|
2022-10-27 17:51:30 +08:00
|
|
|
|
Debug.Log($"Jump!");
|
2022-10-27 12:32:06 +08:00
|
|
|
|
}
|
2022-10-27 17:51:30 +08:00
|
|
|
|
Debug.Log($"{Transform.LocalPosition.y}");
|
2022-10-27 12:32:06 +08:00
|
|
|
|
}
|
2022-11-01 00:11:09 +08:00
|
|
|
|
|
|
|
|
|
protected override void onCollisionEnter(CollisionInfo info)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log($"Collision Enter: {info.GameObject.Name}");
|
|
|
|
|
}
|
|
|
|
|
protected override void onCollisionStay(CollisionInfo info)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log($"Collision Stay: {info.GameObject.Name}");
|
|
|
|
|
}
|
|
|
|
|
protected override void onCollisionExit(CollisionInfo info)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log($"Collision Exit: {info.GameObject.Name}");
|
|
|
|
|
}
|
|
|
|
|
protected override void onTriggerEnter(CollisionInfo info)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log($"Trigger Enter: {info.GameObject.Name}");
|
|
|
|
|
}
|
|
|
|
|
protected override void onTriggerStay(CollisionInfo info)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log($"Trigger Stay: {info.GameObject.Name}");
|
|
|
|
|
}
|
|
|
|
|
protected override void onTriggerExit(CollisionInfo info)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log($"Trigger Exit: {info.GameObject.Name}");
|
|
|
|
|
}
|
2022-10-27 12:32:06 +08:00
|
|
|
|
}
|