using UnityEngine;
public class Player : MonoBehaviour
{
public bool isOut = false; // Whether the player is tagged out or not
// Method to handle the player getting tagged
public void TagOut()
{
isOut = true;
// Add any additional effects when the player is tagged out, such as animations or effects
Debug.Log(gameObject.name + " is tagged out!");
}
}
using UnityEngine;
public class PalmGun : MonoBehaviour
{
public float shootRange = 50f; // Range of the shot
public float shootCooldown = 1f; // Cooldown between shots
private float nextShootTime = 0f;
public Camera playerCamera; // Camera attached to the player to detect where they're aiming
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(0) && Time.time > nextShootTime) // 0 is the left mouse button
{
Shoot();
nextShootTime = Time.time + shootCooldown; // Reset the cooldown
}
}
void Shoot()
{
RaycastHit hit;
Ray ray = playerCamera.ScreenPointToRay(Input.mousePosition); // Cast a ray from the camera
if (Physics.Raycast(ray, out hit, shootRange))
{
// Check if the shot hits a player
Player hitPlayer = hit.collider.GetComponent();
if (hitPlayer != null && !hitPlayer.isOut)
{
hitPlayer.TagOut(); // Tag the player out if hit
}
}
}
}