Tanks Unity Tutorial
来源:互联网 发布:网络诗歌在哪里发布 编辑:程序博客网 时间:2024/05/22 15:39
YouTube地址:https://www.youtube.com/watch?v=rkQmXcQRpTw
Collider . IsTrigger means it doesn't have a solid surface to it can intersect,but it can send a callback to script ,i've now entered another trigger or another collider
1. 给炮弹设置Collider:
Layers : grouping things together in someway that want to use to either include or exclude them from something.
Shell设置:
ShellExplosion.cs 处理碰撞出发以后,只对特定Layer的对象产生影响。Tank 我们设置了 player layer
Collider[] colliders = Physics.OverlapSphere(transform.position, m_ExplosionRadius, m_TankMask);
using UnityEngine;public class ShellExplosion : MonoBehaviour{ public LayerMask m_TankMask; public ParticleSystem m_ExplosionParticles; public AudioSource m_ExplosionAudio; public float m_MaxDamage = 100f; public float m_ExplosionForce = 1000f; public float m_MaxLifeTime = 2f; public float m_ExplosionRadius = 5f; private void Start() { Destroy(gameObject, m_MaxLifeTime); } private void OnTriggerEnter(Collider other) { // Find all the tanks in an area around the shell and damage them. Collider[] colliders = Physics.OverlapSphere(transform.position, m_ExplosionRadius, m_TankMask); for (int i = 0; i < colliders.Length; i++ ) { Rigidbody targetRigidbody = colliders[i].GetComponent<Rigidbody>(); if (!targetRigidbody) { continue; } targetRigidbody.AddExplosionForce(m_ExplosionForce,transform.position,m_ExplosionRadius); TankHealth targetHealth = targetRigidbody.GetComponent<TankHealth>(); if (!targetHealth) continue; float damage = CalculateDamage(targetRigidbody.transform.position); targetHealth.TakeDamage(damage); } m_ExplosionParticles.transform.parent = null; m_ExplosionParticles.Play(); m_ExplosionAudio.Play(); Destroy(m_ExplosionParticles.gameObject,m_ExplosionParticles.duration); Destroy(gameObject); } private float CalculateDamage(Vector3 targetPosition) { // Calculate the amount of damage a target should take based on it's position. Vector3 explosionTarget = targetPosition - transform.position; float explosionDistance = explosionTarget.magnitude; float relativeDistance = (m_ExplosionRadius - explosionDistance) / m_ExplosionRadius; float damage = relativeDistance * m_MaxDamage; damage = Mathf.Max(0f, damage); return damage; }}
0 0
- Tanks Unity Tutorial
- Tanks Unity Tutorial
- Tanks Unity Tutorial
- Tanks Unity Tutorial
- Tanks Unity Tutorial
- Tanks Unity Tutorial
- Tanks Unity Tutorial
- Tanks Unity Tutorial
- Tanks!Tutorial初学者可能会出现的问题
- Unity学习之Tanks官网教程
- Unity 3D官方教程——Tanks!学习记录
- unity NGUI Tutorial Tools
- unity官方教程Tanks《坦克大战》中摄像机size的调整的疑问
- Unity iPhone Touch Animation Tutorial
- unity NUGUI tutorial the basics
- unity NGUI Tutorial context menus
- unity NGUI Tutorial event system
- unity NGUI tutorial more events
- MDM9x35MDM9x35启动流程简介
- 对闭包的理解
- 快上车!EventBus使用
- MySQL查询根据名字段重复内容只显示最新的一条
- 1068. Find More Coins (30)
- Tanks Unity Tutorial
- e.target
- c 函数别名
- npm的使用
- js原型与原型链的理解
- 不同操作系统换行符的区别
- js图片压缩-H5
- 补3
- Unity自定义宏