本文整理汇总了C#中UnityEngine.Collider类的典型用法代码示例。如果您正苦于以下问题:C# Collider类的具体用法?C# Collider怎么用?C# Collider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Collider类属于UnityEngine命名空间,在下文中一共展示了Collider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnTriggerExit
public void OnTriggerExit(Collider other)
{
if (list.Contains(other.gameObject))
{
list.Remove(other.gameObject);
}
}
示例2: OnTriggerEnter
private void OnTriggerEnter(Collider col)
{
Destructible destObj = col.gameObject.GetComponentInParent<Destructible>();
// If it has a rigidbody, apply force
Rigidbody rbody = col.attachedRigidbody;
if (rbody != null && !rbody.isKinematic)
rbody.AddExplosionForce(blastForce, origin, 0f, 0.5f);
// Check for Chip-Away Debris
ChipAwayDebris chipAwayDebris = col.gameObject.GetComponent<ChipAwayDebris>();
if (chipAwayDebris != null)
{
if (UnityEngine.Random.Range(1, 100) > 50) // Do this about half the time...
{
chipAwayDebris.BreakOff(blastForce, origin, 0f, 0.5f);
return; //Skip the destructible check if the debris hasn't chipped away yet.
}
else
return;
}
// If it's a destructible object, apply damage
if (destObj != null)
{
destObj.ApplyExplosiveDamage(new ExplosionInfo()
{
BlastForce = blastForce,
Position = origin,
Radius = 0f,
UpwardModifier = 0.5f
});
}
}
示例3: OnTriggerEnter
void OnTriggerEnter(Collider col)
{
if (col.tag == "Fire")
{
hasFireContact = true;
}
}
示例4: OnTriggerEnter
public override void OnTriggerEnter(Collider collider)
{
if(collider.gameObject.GetComponent<UnitPlayer>()!=null){
GameControl.GameOver(true);
Triggered();
}
}
示例5: OnTriggerExit
void OnTriggerExit (Collider other)
{
if (other.gameObject == player)
{
shouldDamage = false;
}
}
示例6: OnTriggerEnter
public void OnTriggerEnter(Collider other)
{
explosionEmitter.Emit(200);
volumeController.Stop();
mGameOver = true;
Invoke ("StartOver", 1);
}
示例7: OnTriggerEnter
void OnTriggerEnter(Collider coll)
{
if (coll.gameObject.tag == "Player")
{
inTrigger = true;
}
}
示例8: OnTriggerEnter
// OnTriggerEnter is called when the agent runs into a trigger that specifies what task to run text
public override void OnTriggerEnter(Collider other)
{
TriggerType triggerType = null;
if ((triggerType = other.GetComponent<TriggerType>()) != null) {
nextTaskIndex = (int)triggerType.triggerType;
}
}
示例9: ProcessWeaponCollision
protected virtual void ProcessWeaponCollision(Collider collider, Vector3 dir, Vector3 hitPoint)
{
Vector3 direction = -dir * hitForce;
MonsterController monsterController = collider.transform.GetComponentInParent<MonsterController>();
if (monsterController != null)
{
target = monsterController.gameObject;
// targetRigidbody = target.GetComponent<Rigidbody>();
monsterController.Hit(collider,direction, hitPoint, damage);
}
int effectNum;
if (effects == null)
{
effectNum = 0;
}
else
{
effectNum = effects.Length;
}
if (effectNum > 0)
{
int eindex = Random.Range(0, effectNum);
GameObject go = (GameObject)GameObject.Instantiate(effects[eindex], hitPoint, Quaternion.identity);
Object.Destroy(go, 1);
}
}
示例10: OnTriggerStay
private void OnTriggerStay( Collider other ) {
if ( other.tag != SRTags.Ball ) { return; }
Vector3 direction = other.transform.position - transform.position;
Debug.DrawLine( transform.position, transform.position + direction );
float force = ForceStrength * CalculateForceMultiplier( direction.magnitude ) * (int)Mode;
other.attachedRigidbody.AddForce( direction * force );
}
示例11: OnTriggerEnter
void OnTriggerEnter(Collider collider) {
Rigidbody otherRigidbody = collider.attachedRigidbody;
if (otherRigidbody == null || collider.Equals(justHit) || !collider.CompareTag("TennisBall")) {
return;
}
justHit = collider;
justHitCooldown = .5f;
bool forehandBackhand = (new Plane(transform.up, transform.position)).GetSide(transform.position + velocityVector);
Vector3 raquetNormal = forehandBackhand ? transform.up : transform.up * -1;
Vector3 reflectedVec = Vector3.zero;
if (velocityVector.magnitude < 1f) {
reflectedVec = Vector3.Reflect(otherRigidbody.velocity, raquetNormal);
} else {
Vector3 vel = otherRigidbody.velocity.normalized;
Vector3 reflectedBallVel = new Vector3(vel.x, -vel.y, -vel.z);
reflectedVec = (reflectedBallVel + raquetNormal * RaquetAnglePriority) / (RaquetAnglePriority + 1);
}
otherRigidbody.velocity = Vector3.ClampMagnitude((reflectedVec * (1 + velocityVector.magnitude)) * Bounciness, MaxHitSpeed);
RaquetAudioSource.volume = Mathf.Min(Mathf.Pow(otherRigidbody.velocity.magnitude / 5f, 5f), 1f);
RaquetAudioSource.Play();
TrailRenderer trail = collider.GetComponent<TrailRenderer>();
trail.enabled = true;
}
示例12: SphereCastProvider
public SphereCastProvider(Collider c)
{
Ensure.ArgumentNotNull(c, "c");
var t = c.transform;
var scale = t.lossyScale;
var sc = c as SphereCollider;
var cc = c as CapsuleCollider;
if (sc != null)
{
var scaling = Mathf.Max(scale.x, scale.y, scale.z);
_radius = sc.radius * scaling;
_centerOffsetY = sc.center.y * scaling;
}
else if (cc != null && cc.direction == 1)
{
_radius = cc.radius * Mathf.Max(scale.x, scale.z);
_centerOffsetY = (cc.center.y * scale.y) - Mathf.Max((cc.height * scale.y * 0.5f) - _radius, 0f);
}
else
{
throw new ArgumentException("A sphere cast provider only works with sphere or vertical capsule colliders!");
}
}
示例13: OnTriggerEnter
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag ("Pick Up"))
{
audioSource.PlayOneShot(audioCollect);
other.gameObject.SetActive (false);
ScoreManager.score += scoreValue;
}
else if (other.gameObject.CompareTag ("HpItem"))
{
audioSource.PlayOneShot (audioCollect);
other.gameObject.SetActive (false);
playerHealth.Recovery(healthPoint);
}
else if (other.gameObject.CompareTag ("ExpItem"))
{
audioSource.PlayOneShot (audioCollect);
other.gameObject.SetActive (false);
playerLevel.ExpUpItem(expPoint);
}
}
示例14: SetHeadsetCollisionEvent
protected HeadsetCollisionEventArgs SetHeadsetCollisionEvent(Collider collider, Transform currentTransform)
{
HeadsetCollisionEventArgs e;
e.collider = collider;
e.currentTransform = currentTransform;
return e;
}
示例15: OnTriggerEnter
void OnTriggerEnter(Collider other)
{
if(!sequenceToPlay)
{
Debug.LogWarning("You have triggered a sequence in your scene, however, you didn't assign it a Sequence To Play", gameObject);
return;
}
if(sequenceToPlay.IsPlaying)
return;
if(other.CompareTag("MainCamera") && isMainCameraTrigger)
{
sequenceToPlay.Play();
return;
}
if(other.CompareTag("Player") && isPlayerTrigger)
{
sequenceToPlay.Play();
return;
}
if(other.gameObject == triggerObject)
{
sequenceToPlay.Play();
return;
}
}