finsihed castle walls, adding attack, block and kick aniamtions and input. Started on NPCdiagloue system
This commit is contained in:
@@ -14,6 +14,11 @@ namespace StarterAssets
|
||||
#endif
|
||||
public class ThirdPersonController : MonoBehaviour
|
||||
{
|
||||
|
||||
[Header("Animation")]
|
||||
[Tooltip("Animator component reference")]
|
||||
public Animator Animator;
|
||||
|
||||
[Header("Player")]
|
||||
[Tooltip("Move speed of the character in m/s")]
|
||||
public float MoveSpeed = 2.0f;
|
||||
@@ -98,6 +103,8 @@ namespace StarterAssets
|
||||
private int _animIDFreeFall;
|
||||
private int _animIDMotionSpeed;
|
||||
|
||||
private Transform _currentTarget; // Track the currently targeted object
|
||||
|
||||
#if ENABLE_INPUT_SYSTEM
|
||||
private PlayerInput _playerInput;
|
||||
#endif
|
||||
@@ -159,6 +166,29 @@ namespace StarterAssets
|
||||
JumpAndGravity();
|
||||
GroundedCheck();
|
||||
Move();
|
||||
|
||||
CheckForObjectInformation(); // Call the new Raycast function
|
||||
|
||||
if (Input.GetMouseButtonUp(0))
|
||||
{
|
||||
PlayerAttack(); // Call the attack function when the left mouse button is pressed
|
||||
} // Left mouse button
|
||||
|
||||
// Block when the right mouse button is pressed
|
||||
if (Input.GetMouseButton(1))
|
||||
{
|
||||
PlayerBlock(); // Start the block animation
|
||||
}
|
||||
else
|
||||
{
|
||||
Animator.SetBool("Block", false); // Stop the block animation when the button is released
|
||||
}
|
||||
|
||||
if (Input.GetKeyUp(KeyCode.F))
|
||||
{
|
||||
PlayerKick(); // Call the kick function when the F button is pressed
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
@@ -211,6 +241,41 @@ namespace StarterAssets
|
||||
_cinemachineTargetYaw, 0.0f);
|
||||
}
|
||||
|
||||
private void CheckForObjectInformation()
|
||||
{
|
||||
// Define the sphere cast starting point and direction
|
||||
Vector3 origin = transform.position;
|
||||
Vector3 direction = transform.forward;
|
||||
float sphereRadius = 0.5f; // Adjust the radius as needed
|
||||
float maxDistance = 4.0f; // Adjust the distance as needed
|
||||
RaycastHit hit;
|
||||
|
||||
// Perform the sphere cast
|
||||
if (Physics.SphereCast(origin, sphereRadius, direction, out hit, maxDistance))
|
||||
{
|
||||
// Check if the hit object has the ObjectInformation component
|
||||
ObjectInformation objectInfo = hit.collider.GetComponent<ObjectInformation>();
|
||||
if (objectInfo != null)
|
||||
{
|
||||
// If the player is looking at a new object, update the pop-up
|
||||
if (_currentTarget != hit.transform)
|
||||
{
|
||||
_currentTarget = hit.transform; // Update the current target
|
||||
PopUpManager.instance.ShowPopUp(objectInfo.objectName, objectInfo.objectDescription, hit.transform);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// If the sphere cast doesn't hit anything, hide the pop-up
|
||||
if (_currentTarget != null)
|
||||
{
|
||||
_currentTarget = null; // Clear the current target
|
||||
PopUpManager.instance.gameObject.SetActive(false); // Hide the pop-up
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Move()
|
||||
{
|
||||
// set target speed based on move speed, sprint speed and if sprint is pressed
|
||||
@@ -388,5 +453,19 @@ namespace StarterAssets
|
||||
AudioSource.PlayClipAtPoint(LandingAudioClip, transform.TransformPoint(_controller.center), FootstepAudioVolume);
|
||||
}
|
||||
}
|
||||
public void PlayerAttack()
|
||||
{
|
||||
Animator.SetTrigger("Attack");
|
||||
}
|
||||
|
||||
public void PlayerBlock()
|
||||
{
|
||||
Animator.SetBool("Block", true);
|
||||
}
|
||||
|
||||
public void PlayerKick()
|
||||
{
|
||||
Animator.SetTrigger("Kick");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user