BomberUnits
...a Unity learning project
Destructible Class Reference

Destructibles have hit points and are affected by damage sources. More...

+ Inheritance diagram for Destructible:
+ Collaboration diagram for Destructible:

Public Member Functions

void Hit (Explodeable.Damage dmg)
 Applies the given damage and destroys this object if hitpoints reach zero or lower.
 
void Kill (Explodeable.Damage dmg)
 
bool IsAlive ()
 
void OnPhotonSerializeView (PhotonStream stream, PhotonMessageInfo info)
 Synchronization of hitpoints via Photon. More...
 

Public Attributes

GameObject brokenObjectPrefab = null
 
GameObject [] brokenParts = null
 
float destroyedAfter = 0f
 Set inf to never destroy.
 
int hitpoints = 1
 Default >0 so as to not trigger anything on startup.
 
bool piecesShallCollide = true
 

Private Member Functions

List< GameObject > Break ()
 The Break function returns a list of GOs which represent the broken parts of the object this script is attached to. More...
 
void Throw (GameObject piece, Explodeable.Damage dmg)
 Activates Physics for the piece and applies the damage force.
 
void SelfDestruct ()
 

Detailed Description

Destructibles have hit points and are affected by damage sources.

They break and their parts can be thrown by the damage source when their HP reach zero. The Destructible also checks for a LootSpawner to spawn stuff on destruction.

Definition at line 11 of file Destructible.cs.

Member Function Documentation

◆ Break()

List<GameObject> Break ( )
inlineprivate

The Break function returns a list of GOs which represent the broken parts of the object this script is attached to.

There are two ways to use this: a) Set a different 'broken' version of the model in the 'brokenObjectPrefab' slot. The script expects to find the broken pieces as first-level children directly underneath the prefab object. b) Add children of this GO to the 'brokenParts' list. All parts are expected to have suitably weighted rigidbodies attached, which may be disabled though.

If you do both, option a) will be preferred by the script.

Also breaking an object may spawn loot.

Definition at line 84 of file Destructible.cs.

◆ OnPhotonSerializeView()

void OnPhotonSerializeView ( PhotonStream  stream,
PhotonMessageInfo  info 
)
inline

Synchronization of hitpoints via Photon.

Each value has to be serializable and is written and read to/from the stream in sequence. The data is transferred unreliable and should thus not be used to trigger any game mechanics, only visuals! TODO: Is this ok here, then? How about using RPCs?

Definition at line 61 of file Destructible.cs.


The documentation for this class was generated from the following file: