111
This commit is contained in:
@@ -24,7 +24,7 @@ namespace StudyCase2
|
||||
model = transform.Find("Model");
|
||||
animator = model.GetComponentInChildren<Animator>();
|
||||
vCam = transform.Find("Virtual Camera").GetComponent<Cinemachine.CinemachineVirtualCamera>();
|
||||
inputAction = Resources.Load<InputActionAsset>("Player");
|
||||
inputAction = Resources.Load<InputActionAsset>("PlayerInputActions");
|
||||
inputAction.FindAction("Move").started += OnMove;
|
||||
inputAction.FindAction("Move").performed += OnMove;
|
||||
inputAction.FindAction("Move").canceled += OnMove;
|
||||
@@ -55,7 +55,7 @@ namespace StudyCase2
|
||||
}
|
||||
public void OnJump(InputAction.CallbackContext context)
|
||||
{
|
||||
if (context.performed && characterController.isGrounded)
|
||||
if (characterController.isGrounded)
|
||||
{
|
||||
moveDir.y = jumpSpeed;
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace StudyCase3
|
||||
model = transform.Find("Model");
|
||||
animator = model.GetComponentInChildren<Animator>();
|
||||
vCam = transform.Find("Virtual Camera").GetComponent<Cinemachine.CinemachineVirtualCamera>();
|
||||
inputAction = Resources.Load<InputActionAsset>("Player");
|
||||
inputAction = Resources.Load<InputActionAsset>("PlayerInputActions");
|
||||
inputAction.FindAction("Move").started += OnMove;
|
||||
inputAction.FindAction("Move").performed += OnMove;
|
||||
inputAction.FindAction("Move").canceled += OnMove;
|
||||
@@ -49,6 +49,12 @@ namespace StudyCase3
|
||||
inputAction.FindAction("Pick").performed += OnPickUp;
|
||||
inputAction.Enable();
|
||||
itemRoot = transform.Find("ItemRoot");
|
||||
if (lineRenderer == null)
|
||||
{
|
||||
lineRenderer = gameObject.AddComponent<LineRenderer>();
|
||||
lineRenderer.material = new Material(Shader.Find("Universal Render Pipeline/2D/Sprite-Unlit-Default"));
|
||||
lineRenderer.useWorldSpace = true;
|
||||
}
|
||||
}
|
||||
private void Update()
|
||||
{
|
||||
@@ -95,7 +101,12 @@ namespace StudyCase3
|
||||
}
|
||||
void CheckRayHit()
|
||||
{
|
||||
if (pickMode != PickMode.RayCast) return;
|
||||
lineRenderer.enabled = useDrawRay;
|
||||
if (pickMode != PickMode.RayCast)
|
||||
{
|
||||
useDrawRay = false;
|
||||
return;
|
||||
}
|
||||
Ray ray = new Ray(model.position, model.forward);
|
||||
RaycastHit hit;
|
||||
if (Physics.Raycast(ray, out hit, maxDistance, layerMask))
|
||||
@@ -120,17 +131,6 @@ namespace StudyCase3
|
||||
}
|
||||
void DrawRay(Vector3 startPos, Vector3 endPos, Color color)
|
||||
{
|
||||
if (lineRenderer == null)
|
||||
{
|
||||
lineRenderer = gameObject.AddComponent<LineRenderer>();
|
||||
lineRenderer.material = new Material(Shader.Find("Universal Render Pipeline/2D/Sprite-Unlit-Default"));
|
||||
lineRenderer.useWorldSpace = true;
|
||||
}
|
||||
if (!useDrawRay)
|
||||
{
|
||||
lineRenderer.enabled = false;
|
||||
return;
|
||||
}
|
||||
lineRenderer.startColor = lineRenderer.endColor = color;
|
||||
lineRenderer.startWidth = lineRenderer.endWidth = 0.1f;
|
||||
lineRenderer.positionCount = 2;
|
||||
|
||||
Reference in New Issue
Block a user