private void Fly() { if (m_target == null || ((PlayerBehaviour)m_target.Behaviour).FSMSystem.CurrentStateID == StateID.PlayerDie) { m_IsAttract = false; m_IsInit = false; m_boxStatus = BoxStatus.unpick; if (m_eff_fly != null) { Destroy(m_eff_fly); } SetDamageChildActive(true); return; } Vector3 targetPos = m_target.GO.transform.position; //targetPos.y = 0; Vector3 myPos = m_thisTransfrom.position; //myPos.y = 0; Vector3 v = targetPos - myPos; m_thisTransfrom.position += (v.normalized * m_fly_speed * Time.deltaTime); if (Vector3.Distance(m_thisTransfrom.position, m_target.GO.transform.position) <= CommonDefineManager.Instance.CommonDefine.DropItem_RadiusParam) { GameObject pickEff = UI.CreatObjectToNGUI.InstantiateObj(GameManager.Instance.DamageFactory.Eff_AutomaticPick_BePick_Prefab, m_target.GO.transform); pickEff.AddComponent <DestroySelf>(); DamageBehaviour damageBehaviour = GetComponent <DamageBehaviour>(); if (damageBehaviour != null) { damageBehaviour.BePickUp(m_target.EntityDataStruct.SMsg_Header.uidEntity); } m_boxStatus = BoxStatus.none; } }
public void MyUpdate() { Move(); if (target == null) { return; } //get the distance between the chaser and the target float distance = Vector2.Distance(transform.position, target.position); //so long as the chaser is farther away than the minimum distance, move towards it at rate speed. if (distance < MINDIST) { HealthBehaviour health = target.GetComponent(typeof(HealthBehaviour)) as HealthBehaviour; DamageBehaviour damage = gameObject.GetComponent(typeof(DamageBehaviour)) as DamageBehaviour; if (health != null && damage != null) { if (!health.IsImmune) { target.GetComponent <AudioSource>().Play(); } health.ApplyDamage(damage.DamageAmount); } } if (target.position.x > transform.position.x && xMoveDirection < 0 || target.position.x < transform.position.x && xMoveDirection > 0) { xMoveDirection *= -1; } }
//吸引 private void Attract() { if (m_target == null) { m_IsAttract = false; m_IsInit = false; return; } /* * Vector3 v = m_target.GO.transform.position - transform.position; * transform.Translate(v.normalized * ATTRACT_SPEED); * if (Vector3.Distance(transform.position, m_target.GO.transform.position) <= ATTRACT_SPEED) * { * DamageBehaviour damageBehaviour = GetComponent<DamageBehaviour>(); * if (damageBehaviour != null) * { * damageBehaviour.BePickUp(m_target.EntityDataStruct.SMsg_Header.uidEntity); * } * } *///去掉吸引,直接拾取 DamageBehaviour damageBehaviour = GetComponent <DamageBehaviour>(); if (damageBehaviour != null) { damageBehaviour.BePickUp(m_target.EntityDataStruct.SMsg_Header.uidEntity); } m_boxStatus = BoxStatus.none; }
void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.CompareTag("Bullet")) { HealthBehaviour health = gameObject.GetComponent(typeof(HealthBehaviour)) as HealthBehaviour; DamageBehaviour damage = collision.gameObject.GetComponent(typeof(DamageBehaviour)) as DamageBehaviour; if (health != null && damage != null) { health.ApplyDamage(damage.DamageAmount); } } }
void Start() { health = GetComponent <HealthController>(); KnockBehav = GetComponent <KnockbackBehaviour>(); body = GetComponent <Rigidbody2D>(); moveInput = true; DmgBehav = new DamageBehaviour(this); BaseStats = new Stats(5, 5); BaseStats.maxhealth = health.MaxHealth; TotalStats = new Stats(BaseStats); init(); }
protected virtual void Start() { _objectPool = ObjectPooler.Instance; _rigidBody2D = GetComponent <Rigidbody2D>(); _spriteRenderer = GetComponent <SpriteRenderer>(); _input = GetComponent <Input>(); _movementBehaviour = GetComponent <MovementBehaviour>(); _jumpBehaviour = GetComponent <JumpBehaviour>(); _playerCheckBehaviour = GetComponent <PlayerCheckBehaviour>(); _dashBehaviour = GetComponent <DashBehaviour>(); _damageBehaviour = GetComponent <DamageBehaviour>(); _audioBehaviour = GetComponent <AudioBehaviour>(); _specialEffectBehaviour = GetComponent <SpecialEffectBehaviour>(); _scoreBehaviour = GetComponent <ScoreBehaviour>(); }
//判断范围内最近英雄拾取 public void JudgeAndPickUp() { if (m_boxStatus != BoxStatus.unpick) { return; } float lastDis = 0; m_HerosList.ApplyAllItem(p => { if (p != null && p.GO != null) { float dis = Vector3.Distance(m_thisTransfrom.position, p.GO.transform.position); // TraceUtil.Log("[Distance]"+dis); if (dis > lastDis) { m_target = p; dis = lastDis; // m_IsAttract = true; } } }); GameObject dust = (GameObject)Instantiate(GameManager.Instance.DamageFactory.Eff_AutomaticPick_Start_Prefab); dust.transform.position = m_thisTransfrom.position; dust.AddComponent <DestroySelf>(); GameObject flyEff = (GameObject)Instantiate(GameManager.Instance.DamageFactory.Eff_AutomaticPick_Fly_Prefab); flyEff.transform.position = new Vector3(m_thisTransfrom.position.x, 1, m_thisTransfrom.position.z); //GameObject flyEff = UI.CreatObjectToNGUI.InstantiateObj(GameManager.Instance.DamageFactory.Eff_AutomaticPick_Fly_Prefab,m_thisTransfrom); flyEff.transform.parent = null; BoxFlyEffect effectBehaviour = flyEff.AddComponent <BoxFlyEffect>(); effectBehaviour.Init(m_target, CommonDefineManager.Instance.CommonDefine.AutoPickup_Speed, CommonDefineManager.Instance.CommonDefine.DropItem_RadiusParam); //上发拾取 DamageBehaviour damageBehaviour = GetComponent <DamageBehaviour>(); if (damageBehaviour != null) { damageBehaviour.BePickUp(m_target.EntityDataStruct.SMsg_Header.uidEntity); } m_boxStatus = BoxStatus.none; }
private void SetDamageChildActive(bool isActive) { DamageBehaviour damageBehaviour = GetComponent <DamageBehaviour>(); if (damageBehaviour.TitleRef != null) { damageBehaviour.TitleRef.SetActive(isActive); } int childCount = m_thisTransfrom.childCount; if (childCount > 0) { for (int i = childCount - 1; i >= 0; i--) { m_thisTransfrom.GetChild(i).gameObject.SetActive(isActive); } } }
/// <summary> /// Called when the inspector is opened or changed. /// </summary> public override void OnInspectorGUI() { Skill skill = target as Skill; // Iterate through all of the skill variables SerializedProperty it = serializedObject.GetIterator(); if (it.NextVisible(true)) { while (it.NextVisible(false)) // Loop through all the skill variables { if (it.name == "instantBehaviours") // Special handling for the instant behaviours list { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); EditorGUILayout.LabelField("Instant Behaviours", EditorStyles.boldLabel); // Create an editor for each skill behaviour for (int i = 0; i < skill.instantBehaviours.Count; i++) { if (i != 0) { DrawHorizontalLine(Color.gray); } if (skill.instantBehaviours[i] != null) { CreateEditor(skill.instantBehaviours[i]).OnInspectorGUI(); // Button for removing this behaviour if (GUILayout.Button("Remove behaviour", EditorStyles.miniButton)) { DestroyImmediate(skill.instantBehaviours[i], true); skill.instantBehaviours.RemoveAt(i); } } } } else if (it.name == "damageBehaviours") // Special handling for the damage behaviours list { EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); EditorGUILayout.LabelField("Damage Behaviours", EditorStyles.boldLabel); // Create an editor for each skill behaviour for (int i = 0; i < skill.damageBehaviours.Count; i++) { if (i != 0) { DrawHorizontalLine(Color.gray); } if (skill.damageBehaviours[i] != null) { CreateEditor(skill.damageBehaviours[i]).OnInspectorGUI(); // Button for removing this behaviour if (GUILayout.Button("Remove behaviour", EditorStyles.miniButton)) { DestroyImmediate(skill.damageBehaviours[i], true); skill.damageBehaviours.RemoveAt(i); } } } EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); } else { EditorGUILayout.PropertyField(serializedObject.FindProperty(it.name), true); // Default inspector } } } // Section for adding new behaviours EditorGUILayout.LabelField("Add a new behaviour", EditorStyles.boldLabel); behaviourType = (BehaviourType)EditorGUILayout.EnumPopup("Behaviour Type:", behaviourType); UpdateBehaviourSelections(); selectedOption = EditorGUILayout.Popup("Behaviour: ", selectedOption, options); // Button for adding a new behaviour if (GUILayout.Button("Add new behaviour")) { if (behaviourType == BehaviourType.Instant) { // Add it to the list of behaviours InstantBehaviour behaviour = CreateInstance(options[selectedOption]) as InstantBehaviour; AssetDatabase.AddObjectToAsset(behaviour, skill); skill.instantBehaviours.Add(behaviour); } else { // Add it to the list of behaviours DamageBehaviour behaviour = CreateInstance(options[selectedOption]) as DamageBehaviour; AssetDatabase.AddObjectToAsset(behaviour, skill); skill.damageBehaviours.Add(behaviour); } } // Save changes serializedObject.ApplyModifiedProperties(); }
IEnumerator Throw(float strength) { float normalizedStrengthRatio = Mathf.InverseLerp(ProjectileData.throwStrengthCurve.Evaluate(0), ProjectileData.throwStrengthCurve.Evaluate(throwStrengthCurveEndTime), strength); //sound! PogChamp if (ProjectileData.throwSounds.Length > 0) { AudioClip randomSFX = ProjectileData.throwSounds[Random.Range(0, ProjectileData.throwSounds.Length)]; weaponAudioSource.PlayOneShot(randomSFX); } //apply camera shake mainCamera.cameraShakeCurve = ProjectileData.cameraShakeCurve; mainCamera.cameraShakeCurveEndTime = cameraShakeCurveEndTime; mainCamera.cameraShakeCurrentTime = 0; //do... while loop so the code is ran at least once no matter the condition int i = 0; do { GameObject newShot = Instantiate(ProjectileData.projectilePrefab); //calculating damage based on power curve //newShot.GetComponent<DamageBehaviour>().damage = Random.Range(ProjectileData.projectileMinDamage, ProjectileData.projectileMaxDamage); newShot.gameObject.transform.position = projectileSource.transform.position; //define bullet base rotation newShot.gameObject.transform.up = Camera.main.ScreenToWorldPoint(Input.mousePosition) - newShot.gameObject.transform.position; //apply random scattering factor Vector3 scattering = new Vector3(0, 0, Random.Range(-ProjectileData.scatteringAngle, ProjectileData.scatteringAngle)); //Debug.Log("Scattering: " + scattering.z); newShot.gameObject.transform.Rotate(scattering); //newShot.gameObject.transform.LookAt(mainCamera.GetComponent<Camera>().ScreenToWorldPoint(Input.mousePosition)); newShot.GetComponent <Rigidbody2D>().AddForce((newShot.gameObject.transform.up) * Mathf.Lerp(ProjectileData.minStrength, ProjectileData.maxStrength, normalizedStrengthRatio)); //ProjectileData.projectileSpeed); Physics2D.IgnoreCollision(newShot.GetComponent <Collider2D>(), Player.Instance.gameObject.GetComponent <Collider2D>(), true); //setting the projectile rotation ProjectileBehaviour projectileBehaviour = newShot.GetComponent <ProjectileBehaviour>(); projectileBehaviour.rotating = true; projectileBehaviour.rotationSpeed = Mathf.Lerp(ProjectileData.minRotationSpeed, ProjectileData.maxRotationSpeed, normalizedStrengthRatio); DamageBehaviour damageBehaviour = newShot.GetComponent <DamageBehaviour>(); damageBehaviour.damage = Mathf.Lerp(ProjectileData.minDamage, ProjectileData.maxDamage, normalizedStrengthRatio); ////debug: assigning Player as default owner //bulletBehaviour.owner = Player.Instance.gameObject; // (poor) ammo management inventoryManager.RemoveFirstItemInInventory(1); i++; } while (i < ProjectileData.ammoSpentPerThrow); //firing delay canShoot = false; yield return(new WaitForSeconds(ProjectileData.throwRate)); canShoot = true; }