void OnEnable() { m_EnemyController = GetComponent <EnemyController>(); m_NavMeshAgent = GetComponent <NavMeshAgent>(); SceneLinkedSMB <GrenadierBehaviour> .Initialise(m_EnemyController.animator, this); fistWeapon.SetOwner(gameObject); fistWeapon.EndAttack(); m_CoreMaterial = coreRenderer.materials[1]; m_OriginalCoreMaterial = m_CoreMaterial.GetColor("_Color2"); m_EnemyController.animator.Play(hashIdleState, 0, Random.value); shield.SetActive(false); m_Damageable = GetComponentInChildren <Damageable>(); }
private void AddHealth(Damageable damageable) { int currentNumberOfHearts = m_HealthIconAnimators.Count; if (currentNumberOfHearts < damageable.maxHitPoints) { for (int i = currentNumberOfHearts; i < damageable.maxHitPoints; i++) { GameObject healthIcon = Instantiate(healthIconPrefab); healthIcon.transform.SetParent(transform); RectTransform healthIconRect = healthIcon.transform as RectTransform; healthIconRect.anchoredPosition = Vector2.zero; healthIconRect.sizeDelta = Vector2.zero; healthIconRect.anchorMin += new Vector2(k_HeartIconAnchorWidth, 0f) * i; healthIconRect.anchorMax += new Vector2(k_HeartIconAnchorWidth, 0f) * i; m_HealthIconAnimators.Add(healthIcon.GetComponent <Animator>()); } } }
protected float m_ShieldActivationTime; //盾的启动时间 void OnEnable() //游戏开始前的准备 { m_EnemyController = GetComponent <EnemyController>(); //获取怪物的敌人控制器组件 m_NavMeshAgent = GetComponent <NavMeshAgent>(); //获得怪物的寻路组件 SceneLinkedSMB <GrenadierBehaviour> .Initialise(m_EnemyController.animator, this); fistWeapon.SetOwner(gameObject); //设置可以使用拳击的对象 fistWeapon.EndAttack(); //默认拳击为停止状态 m_CoreMaterial = coreRenderer.materials[1]; //将核心材质替换为蒙皮过滤器的2号材质 m_OriginalCoreMaterial = m_CoreMaterial.GetColor("_Color2"); //将基础颜色设为核心材质的_Color2的颜色 m_EnemyController.animator.Play(hashIdleState, 0, Random.value); //播放一个随机进度的投掷者站立动画 https://docs.unity3d.com/ScriptReference/Animator.Play.html shield.SetActive(false); //盾关闭 m_Damageable = GetComponentInChildren <Damageable>(); //获得子物体的伤害控制组件 }
private void SetHealth(Damageable damageable) { m_HealthIconAnimators = new List <Animator>(); for (int i = 0; i < damageable.maxHitPoints; i++) { GameObject healthIcon = Instantiate(healthIconPrefab); healthIcon.transform.SetParent(transform); RectTransform healthIconRect = healthIcon.transform as RectTransform; healthIconRect.anchoredPosition = Vector2.zero; healthIconRect.sizeDelta = Vector2.zero; healthIconRect.anchorMin += new Vector2(k_HeartIconAnchorWidth, 0f) * i; healthIconRect.anchorMax += new Vector2(k_HeartIconAnchorWidth, 0f) * i; m_HealthIconAnimators.Add(healthIcon.GetComponent <Animator>()); if (damageable.currentHitPoints < i + 1) { m_HealthIconAnimators[i].Play(m_HashInactiveState); m_HealthIconAnimators[i].SetBool(m_HashActivePara, false); } } }
public void Explosion() { if (explosionPlayer) { explosionPlayer.transform.SetParent(null); explosionPlayer.PlayRandomClip(); } int count = Physics.OverlapSphereNonAlloc(transform.position, explosionRadius, m_ExplosionHitCache, damageMask.value); Damageable.DamageMessage message = new Damageable.DamageMessage { amount = damageAmount, damageSource = transform.position, damager = this, stopCamera = false, throwing = true }; for (int i = 0; i < count; ++i) { Damageable d = m_ExplosionHitCache[i].GetComponentInChildren <Damageable>(); if (d != null) { d.ApplyDamage(message); } } pool.Free(this); m_VFXInstance.gameObject.transform.position = transform.position; m_VFXInstance.time = 0.0f; m_VFXInstance.gameObject.SetActive(true); m_VFXInstance.Play(true); }
private void OnTriggerStay(Collider other) { if ((damagedLayers.value & 1 << other.gameObject.layer) == 0) { return; } Damageable d = other.GetComponentInChildren <Damageable>(); if (d != null && !d.isInvulnerable) { Damageable.DamageMessage message = new Damageable.DamageMessage { damageSource = transform.position, damager = this, amount = amount, direction = (other.transform.position - transform.position).normalized, throwing = false }; d.ApplyDamage(message); } }
private void Update() { Damageable.DamageMessage data; data.damageSource = transform.position; data.amount = 1; data.damager = this; data.stopCamera = false; data.throwing = true; int count = Physics.OverlapSphereNonAlloc(transform.position, m_Collider.radius * transform.localScale.x, sOverlapCache, m_PlayerMask); for (int i = 0; i < count; ++i) { Damageable d = sOverlapCache[i].GetComponent <Damageable>(); if (d != null) { data.direction = d.transform.position - transform.position; d.ApplyDamage(data); } } }
public void ChangeHitPointUI(Damageable damageable) { SetHitPointUI(damageable.currentHitPoints); }