You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.3 KiB
60 lines
1.3 KiB
10 years ago
|
using UnityEngine;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
|
||
|
namespace Fungus
|
||
|
{
|
||
|
[CommandInfo("Sprite",
|
||
|
"Set Collider",
|
||
|
"Sets all collider (2d or 3d) components on the target objects to be active / inactive")]
|
||
|
[AddComponentMenu("")]
|
||
|
public class SetCollider : Command
|
||
|
{
|
||
|
[Tooltip("A list of gameobjects containing collider components to be set active / inactive")]
|
||
|
public List<GameObject> targetObjects = new List<GameObject>();
|
||
|
|
||
|
[Tooltip("Set to true to enable the collider components")]
|
||
|
public BooleanData activeState;
|
||
|
|
||
|
public override void OnEnter()
|
||
|
{
|
||
|
foreach (GameObject go in targetObjects)
|
||
|
{
|
||
|
if (go != null)
|
||
|
{
|
||
|
// 3D objects
|
||
|
foreach (Collider c in go.GetComponentsInChildren<Collider>())
|
||
|
{
|
||
|
c.enabled = activeState.Value;
|
||
|
}
|
||
|
|
||
|
// 2D objects
|
||
|
foreach (Collider2D c in go.GetComponentsInChildren<Collider2D>())
|
||
|
{
|
||
|
c.enabled = activeState.Value;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Continue();
|
||
|
}
|
||
|
|
||
|
public override string GetSummary()
|
||
|
{
|
||
|
if (activeState.Value)
|
||
|
{
|
||
|
return "Enable " + targetObjects.Count + " collider objects.";
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return "Disable " + targetObjects.Count + " collider objects.";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public override Color GetButtonColor()
|
||
|
{
|
||
|
return new Color32(235, 191, 217, 255);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|