//======================================== // Unity's function //------------------------------ private void Awake() { // try to get it own transform's componenet. if (mAbilityFormat == null) { mAbilityFormat = this.GetComponent <JCS_AbilityFormat>(); } if (mAttackRange != null) { // range must be trigger mAttackRange.isTrigger = true; // disable the trigger EndAttack(); // set defualt attack animation spawn transform. if (mAtkAnimSpawnTrans == null) { // defualt as the collider's transform. mAtkAnimSpawnTrans = mAttackRange.transform; } } // try to get the action from the attack range. if (mApplyDamageTextAction == null) { this.mApplyDamageTextAction = this.GetComponentInChildren <JCS_ApplyDamageTextToLiveObjectAction>(); } if (mSoundPlayer == null) { this.mSoundPlayer = this.GetComponent <JCS_SoundPlayer>(); } // record down the time mRecordTimeToAttackTime = mTimeToActTime; mRecordActTime = mActTime; }
/// <summary> /// Algorithm to do the main action from this event. /// </summary> public void SpawnObjects() { Transform spawnTrans = null; for (int counter = 0; counter < mObjectsToSpawn; ++counter) { // get the random object from the list. spawnTrans = mObjectList.GetRandomObjectFromList(); // check if null. if (spawnTrans == null) { JCS_Debug.LogError( "Spawning object detect that are null references... Could not spawn the object!"); break; } // spawn the object by transform. // and get the object which we just spawned. spawnTrans = (Transform)JCS_Utility.SpawnGameObject(spawnTrans, this.transform.position); // apply random position spawnTrans.transform.position = RandTransform(spawnTrans.position); // apply random rotation spawnTrans.transform.eulerAngles = RandDegree(spawnTrans.eulerAngles); JCS_ApplyDamageTextToLiveObjectAction adtaThis = this.GetComponent <JCS_ApplyDamageTextToLiveObjectAction>(); JCS_ApplyDamageTextToLiveObjectAction adtaSpawned = spawnTrans.GetComponent <JCS_ApplyDamageTextToLiveObjectAction>(); if (adtaThis != null && adtaSpawned != null) { // copy the apply damage text information to spawned object! adtaSpawned.CopyToThis(adtaThis); } } }
/// <summary> /// Shoot a bullet. /// </summary> /// <param name="bulletSpeed"></param> /// <param name="pos"></param> /// <param name="direction"></param> /// <param name="damages"></param> /// <param name="index"></param> /// <param name="inSequence"></param> /// <param name="target"></param> /// <returns></returns> public JCS_Bullet Shoot(float bulletSpeed, Vector3 pos, bool direction, int[] damages, int index = 0, bool inSequence = false, Transform target = null) { if (mPlayer != null) { if (mPlayer.CharacterState != JCS_2DCharacterState.NORMAL) { return(null); } } int hit = damages.Length; Vector3 spawnPos = pos + mSpanwPointOffset; spawnPos = RandTransform(spawnPos); JCS_Bullet bullet = (JCS_Bullet)JCS_Utility.SpawnGameObject(mBullet, spawnPos, mSpawnPoint.rotation); // no object spawns if (bullet == null) { return(null); } // set the attacker. SetAttackerInfo(bullet); float tempBulletSpeed = bulletSpeed; // default: facing left if (!direction) { tempBulletSpeed = -tempBulletSpeed; } // set bullet speed bullet.MoveSpeed = tempBulletSpeed; // Do devication Effect DeviationEffect(bullet.transform); if (bullet is JCS_2DBullet) { bullet.GetComponent <JCS_3DGoStraightAction>().MoveSpeed = bulletSpeed; } if (mTrackSoot && target != null) { JCS_2DTrackAction ta = bullet.GetComponent <JCS_2DTrackAction>(); if (ta != null) { ta.TargetTransform = target; // set to center float newIndex = index - (hit / 2.0f); // apply effect ta.Index = newIndex; } } if (mAbilityFormat != null) { JCS_ApplyDamageTextToLiveObjectAction adta = bullet.GetComponent <JCS_ApplyDamageTextToLiveObjectAction>(); if (adta != null) { // set the Ability Format adta.AbilityFormat = mAbilityFormat; adta.Hit = hit; adta.DamageApplying = damages; // if hit equal to 0, // meaning this bullet is in the sequence if (inSequence) { adta.InSequence = true; } adta.TargetTransform = target; } } // part of the SFX mRandomMultiSoundAction.PlayRandomSound(); return(bullet); }
/// <summary> /// Copy some information from the other. /// </summary> public void CopyToThis(JCS_ApplyDamageTextToLiveObjectAction copy) { this.AbilityFormat = copy.AbilityFormat; this.Hit = copy.Hit; this.AttackerInfo = copy.AttackerInfo; }