本文整理汇总了C#中BoxCollider类的典型用法代码示例。如果您正苦于以下问题:C# BoxCollider类的具体用法?C# BoxCollider怎么用?C# BoxCollider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BoxCollider类属于命名空间,在下文中一共展示了BoxCollider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Start
// Use this for initialization
void Start()
{
oCol = GetComponent<BoxCollider>();
t = transform;
normColSize = oCol.size.x;
float hori = oCol.size.x * t.localScale.x;
float vert = oCol.size.y * t.localScale.y;
float hMargin = Mathf.Min(margin, hori / minMarginDividor);
float vMargin = Mathf.Min(margin, vert / minMarginDividor);
topCol = Instantiate(Resources.Load("colliders/top"), t.position + new Vector3(hMargin, vert - vMargin, 0), t.rotation) as GameObject;
botCol = Instantiate(Resources.Load("colliders/bot"), t.position + new Vector3(hMargin, 0, 0), t.rotation) as GameObject;
rightCol = Instantiate(Resources.Load("colliders/right"), t.position + new Vector3(hori - hMargin, 0, 0), t.rotation) as GameObject;
leftCol = Instantiate(Resources.Load("colliders/left"), t.position, t.rotation) as GameObject;
topCol.transform.localScale = new Vector3(t.localScale.x - hMargin*2/normColSize, vMargin/normColSize, t.localScale.z);
botCol.transform.localScale = new Vector3(t.localScale.x - hMargin*2/normColSize, vMargin/normColSize, t.localScale.z);
rightCol.transform.localScale = new Vector3(hMargin/normColSize, t.localScale.y, t.localScale.z);
leftCol.transform.localScale = new Vector3(hMargin/normColSize, t.localScale.y, t.localScale.z);
Destroy(gameObject);
}
示例2: ClosestPointOnSurface
public static Vector3 ClosestPointOnSurface(BoxCollider collider, Vector3 to)
{
// Cache the collider transform
var ct = collider.transform;
// Firstly, transform the point into the space of the collider
var local = ct.InverseTransformPoint(to);
// Now, shift it to be in the center of the box
local -= collider.center;
// Clamp the points to the collider's extents
var localNorm =
new Vector3(
Mathf.Clamp(local.x, -collider.size.x * 0.5f, collider.size.x * 0.5f),
Mathf.Clamp(local.y, -collider.size.y * 0.5f, collider.size.y * 0.5f),
Mathf.Clamp(local.z, -collider.size.z * 0.5f, collider.size.z * 0.5f)
);
// Select a face to project on
if (Mathf.Abs(localNorm.x) > Mathf.Abs(localNorm.y) && Mathf.Abs(localNorm.x) > Mathf.Abs(localNorm.z))
localNorm.x = Mathf.Sign(localNorm.x) * collider.size.x * 0.5f;
else if (Mathf.Abs(localNorm.y) > Mathf.Abs(localNorm.x) && Mathf.Abs(localNorm.y) > Mathf.Abs(localNorm.z))
localNorm.y = Mathf.Sign(localNorm.y) * collider.size.y * 0.5f;
else if (Mathf.Abs(localNorm.z) > Mathf.Abs(localNorm.x) && Mathf.Abs(localNorm.z) > Mathf.Abs(localNorm.y))
localNorm.z = Mathf.Sign(localNorm.z) * collider.size.z * 0.5f;
// Now we undo our transformations
localNorm += collider.center;
// Return resulting point
return ct.TransformPoint(localNorm);
}
示例3: Awake
void Awake()
{
// Set up references.
playerRigidbody = GetComponent <Rigidbody> ();
Physics.IgnoreLayerCollision(8, 15, true);
boxCol = GetComponent<BoxCollider>();
}
示例4: Awake
void Awake()
{
m_relatedCam = GameObject.Find("MogoMainUI").transform.GetChild(0).GetComponentInChildren<Camera>();
m_relatedCollider = transform.GetComponentInChildren<BoxCollider>();
m_rayHit = new RaycastHit();
}
示例5: Start
void Start()
{
if(isInverted)
{
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
collider = gameObject.GetComponent<BoxCollider>();
gameObject.GetComponent<Animator>().SetBool("Open",opened);
if (opened){
gameObject.GetComponent<Animator>().Play("AlreadyOpenHor");
gameObject.GetComponent<Animator>().Play("AlreadyOpenVer");
collider.enabled = false;
}
else
{
gameObject.GetComponent<Animator>().Play("AlreadyCloseHor");
gameObject.GetComponent<Animator>().Play("AlreadyCloseVer");
collider.enabled = true;
}
}
示例6: OnDisable
void OnDisable()
{
print( "Awake Box spawn area" );
spawnArea = GetComponent<BoxCollider>();
spawnArea.isTrigger = true;
base.OnDisable();
}
示例7: SpawnObjects
/// <summary>
/// Spawns random objects within the box collider bounds.
/// </summary>
public void SpawnObjects()
{
CurrentSpawnedObjects = new GameObject[NumberToSpawn];
Bounds = GetComponent<BoxCollider>();
for (int i = 0; i < NumberToSpawn; i++)
{
// Get random position within this transform.
Vector3 rndPosWithin = new Vector3(Random.Range(-1f, 1f) * Bounds.size.x / 2,
Random.Range(-1f, 1f) * Bounds.size.x / 2,
Random.Range(-1f, 1f) * Bounds.size.z / 2);
rndPosWithin += transform.position;
if (!isObjectTooClose(rndPosWithin))
{
GameObject spawnedObject = (GameObject)Instantiate(ObjectSpawnPrefabs[Random.Range(0, ObjectSpawnPrefabs.Length)], rndPosWithin, Quaternion.identity);
CurrentSpawnedObjects[i] = spawnedObject;
CurrentSpawnedObjects[i].transform.parent = transform;
// Create a child game object, which we will attach the culling sphere to.
GameObject cullingSphere = new GameObject("Culling Sphere");
cullingSphere.transform.position = rndPosWithin;
cullingSphere.transform.parent = spawnedObject.transform;
// We use a sphere collider to determine whether the object should be rendered.
SphereCollider spawnCollider = cullingSphere.AddComponent<SphereCollider>();
spawnCollider.radius = hideSpawnedObjectDistance;
// The CullObject script determines whether to show or hide the object.
CullObject spawnCuller = cullingSphere.AddComponent<CullObject>();
spawnCuller.CullingTarget = CullingTarget;
}
}
}
示例8: Start
new void Start()
{
base.Start ();
AOECollider = muzzlePoint.GetComponent<BoxCollider> ();
AOECollider.size = colliderDisableSize;
}
示例9: Start
// Use this for initialization
void Start()
{
// Reference objects
this.pickUp = gameObject.GetComponent<AudioSource>();
this._renderer = gameObject.GetComponent<Renderer>();
this.boxCollider = gameObject.GetComponent<BoxCollider>();
}
示例10: Start
private void Start()
{
this.rb = base.GetComponent<Rigidbody>();
this.col = base.GetComponent<BoxCollider>();
base.StartCoroutine("doMove");
this.val = UnityEngine.Random.Range(-50f, 50f);
}
示例11: Start
// Use this for initialization
void Start()
{
_camera = Camera.main;
amountToMove = Vector3.zero;
_stats = new playerStats();
_collider = transform.GetComponent<BoxCollider>();
}
示例12: Awake
void Awake()
{
Debug.Log ("Zombie instantiated!");
moveSpeed = 250f;
isIdle = true;
ChaseTarget = null;
transforming = false;
idleCounter = 0;
idleCounterMax = 3f;
idleMoveSpeed = 50f;
targetContact = false;
zombieSlowBy = 20;
transforming = false;
maxTransformTime = 1.5f;
transformTime = maxTransformTime;
idleSoundIndex = Random.Range(0, idle.Length);
alertSoundIndex = Random.Range(0, alert.Length);
zombieDeathIndex = Random.Range(0,zombieDeath.Length);
//Enables idle zombies to 'see' humans and the player
BoxOfSight = (BoxCollider)transform.GetComponent(typeof(BoxCollider));
BoxOfSight.enabled = true;
/* BUG
* Player.laser will collide with BoxOfSight.
* Attempted to assign BoxOfSight.layer = 2 (ignore raycast)
* Could not assign layer to component, assigned to gameobject instead
* Effect: player.laser will not collide with zombies (including BoxOfSight)
*/
BoxOfSight.gameObject.layer = 2;
gameManager = (GameManager)GameObject.Find ("GameManager").GetComponent("GameManager");
}
示例13: Awake
void Awake() {
BoxRef = this.gameObject.AddComponent<BoxCollider>();
ScriptRef = this.gameObject.GetComponent<CartoonExplosionFX>();
ParentRef = this.gameObject.GetComponent<GameObject>();
}
示例14: Start
// Use this for initialization
void Start()
{
door = transform.FindChild("Inside");
doorPanelCollider = door.FindChild("panel").GetComponent<BoxCollider>();
doorRotation = 0;
interactionEnabled = true;
}
示例15: Awake
void Awake()
{
gameObject.AddComponent<MogoFakeClick>().ReletedClassType = ReleadClassType.Type_InsetUI;
m_relatedCollider = transform.GetComponentInChildren<BoxCollider>();
m_rayHit = new RaycastHit();
}