RequireTrigger

  06. Attributes No Comments

When added before a component class will make sure that whenever the component with the attribute is added to GameObjects, a collider will also be present on the same GameObject.

In addition makes sure that the isTrigger property of the collider will match your desired value (default: True).

Attribute Target

Component class

Example

using System;
using UnityEngine;
using Sisus.Attributes;

[RequireTrigger, DisallowMultipleComponent]
public class Checkpoint : MonoBehaviour
{
	public static Action<int> OnCheckpointSaved;

	[Min(1)]
	public int checkpointId = 1;

	void Reset()
	{
		gameObject.isStatic = true;
	}

	void OnTriggerEnter(Collider other)
	{
		if(PlayerPrefs.GetInt("Checkpoint", 0) < checkpointId)
		{
			PlayerPrefs.SetInt("Checkpoint", checkpointId);

			if(OnCheckpointSaved != null)
			{
				OnCheckpointSaved(checkpointId);
			}
		}
	}
}

Example Result

 

See also: RequireCollider