-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStalkerBoltRadiationTutorial.cs
More file actions
112 lines (97 loc) · 4.12 KB
/
StalkerBoltRadiationTutorial.cs
File metadata and controls
112 lines (97 loc) · 4.12 KB
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
using UnityEngine;
public class Radiation : MonoBehaviour
{
public GameObject radiationEffect; // Visual effect for radiation
public float damagePerSecond = 10f; // Damage dealt per second in radiation zone
public GameObject explosionEffect; // Explosion effect prefab
public string throwableTag = "Throwable"; // Tag for throwable objects
private bool isPlayerInZone = false;
private ThirdPersonCharacter player;
void Update()
{
// Apply damage if the player is in the radiation zone
if (isPlayerInZone && player != null)
{
player.health -= damagePerSecond * Time.deltaTime;
player.health = Mathf.Max(player.health, 0); // Clamp health to non-negative values
if (player.health == 0)
{
player.GetComponent<Animator>().SetTrigger("dead");
player.GetComponent<ThirdPersonUserControl>().enabled = false; // Disable player controls
}
}
}
void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
isPlayerInZone = true;
player = other.GetComponent<ThirdPersonCharacter>();
radiationEffect?.SetActive(true); // Activate the radiation visual effect
}
else if (other.CompareTag(throwableTag))
{
TriggerExplosion(other.transform.position);
Destroy(other.gameObject); // Destroy the throwable object
}
}
void OnTriggerExit(Collider other)
{
if (other.CompareTag("Player"))
{
isPlayerInZone = false;
player = null;
radiationEffect?.SetActive(false); // Deactivate the radiation visual effect
}
}
private void TriggerExplosion(Vector3 position)
{
if (explosionEffect != null)
{
Instantiate(explosionEffect, position, Quaternion.identity); // Create an explosion effect
}
// Optional: Add logic to disable the radiation effect temporarily or permanently
}
/*
==================== INTEGRATION TUTORIAL ====================
This script handles radiation damage and throwable object interaction.
1. Player Setup:
- Ensure the player GameObject has the following:
- Components:
- ThirdPersonCharacter
- ThirdPersonUserControl
- Animator
- Rigidbody
- CapsuleCollider
- Tag: "Player"
- Make sure the health, hunger, and thirst sliders are configured in the Unity Editor.
2. Radiation Zone Setup:
- Create a GameObject for the radiation zone (e.g., "RadiationZone").
- Add a BoxCollider (or any Collider) component to the GameObject and set it to "IsTrigger".
- Attach this Radiation script to the GameObject.
- Assign the following fields in the Unity Editor:
- Radiation Effect: Drag a particle system or visual effect prefab.
- Explosion Effect: Drag an explosion prefab.
- Optional: Adjust the `damagePerSecond` field to control the rate of damage.
3. Throwable Object Setup:
- Create a prefab for the throwable object (e.g., "ThrowableObject").
- Add the following components:
- Rigidbody
- Collider (set to non-trigger)
- Tag: "Throwable"
- Optional: Add a script to handle throwing mechanics.
4. Animator:
- Ensure the Animator Controller for the player has a "dead" trigger and a death animation.
5. Functionality:
- Radiation Effect:
- When the player enters the radiation zone, their health decreases over time.
- If health reaches zero, the death animation is triggered, and player controls are disabled.
- Throwable Interaction:
- When a throwable object enters the radiation zone, an explosion effect is instantiated.
- The throwable object is destroyed upon contact.
6. Testing:
- Play the game and ensure the player takes damage in radiation zones.
- Test throwing objects into the radiation zone to trigger explosions.
=============================================================
*/
}