void Attack() { RaycastHit hit; anims.Play(); if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range)) { Debug.Log(hit.transform.name); SimpleAIController target = hit.transform.GetComponent <SimpleAIController>(); if (target != null) { sounds[0].Play(); target.TakeDamage(damage); } else { sounds[1].Play(); } } else { sounds[1].Play(); } attackTimer = 0; }
// Use this for initialization void Awake () { health = 10; ctrl = new SimpleAIController (this, new List<Player>(GameObject.FindObjectsOfType<Player>())); disableFaces2 (); idleFace[Random.Range(0,idleFace.Length)].SetActive (true); StartCoroutine(BackgroundSound()); }
// Use this for initialization protected void Start() { className = this.GetType().ToString(); rb = GetComponent <Rigidbody2D> (); sr = GetComponent <SpriteRenderer> (); colli = GetComponent <Collider2D> (); halfWidth = colli.bounds.extents.x; halfHeight = colli.bounds.extents.y; // build animations anim = GetComponent <Animator> (); AnimationClip[] clips = anim.runtimeAnimatorController.animationClips; foreach (AnimationClip clip in clips) { animationClipTable [clip.name] = clip; } // build actions //actionTable [Action.Type.Attack] = new AttackAction (this); actionTable [Action.Type.Attack] = new AttackShootAction(this); ((AttackShootAction)actionTable [Action.Type.Attack]).SetSprite("Graphic/arrow"); //actionTable [Action.Type.JumpAttack] = new JumpAttackAction (this); actionTable [Action.Type.JumpAttack] = new JumpShootAttackAction(this); ((JumpShootAttackAction)actionTable [Action.Type.JumpAttack]).SetSprite("Graphic/arrow"); //actionTable [Action.Type.Defend] = new RushAction (this); //actionTable [Action.Type.Defend].SetNextAction (Action.Type.Attack); actionTable [Action.Type.Damage] = new DamageAction(this); actionTable [Action.Type.Climb] = new ClimbAction(this); actionTable [Action.Type.Dead] = new DeadAction(this); //actionTable [Action.Type.Rush] = new RushAction (this); // wall jump // edge + jump -> climb up // combo // pick up //actionTable [Action.Type.Attack].SetPlaySpeedByDuration (1f); // default attack AttackArea aa = GetComponentInChildren <AttackArea> (); aa.SetAttacker(this); aa.SetAttack(new SimpleAttack(10)); info = GetComponent <CharacterInfo> (); info.owner = this; info.HPBar = transform.Find("HP/Cur HP").gameObject; SimpleAIController simpleAI = gameObject.AddComponent <SimpleAIController>(); simpleAI.SetReceiver(this); simpleAI.transform.parent = transform; AI = simpleAI; }
static void AttachAIControllerScript(GameObject obj) { //Assign AI Script to the GameObject SimpleAIController AIscript = null; if (obj) { AIscript = obj.AddComponent <SimpleAIController>(); Selection.activeGameObject = obj; } }
void Attack() { RaycastHit hit; if (Physics.Raycast(transform.position, transform.forward, out hit, range)) { Debug.Log(hit.transform.name); SimpleAIController target = hit.transform.GetComponent <SimpleAIController>(); if (target != null) { target.TakeDamage(damage); } } attackTimer = 0; }
void Shoot() { muzzleFlash.Play(); gunshot.Play(); recoil.Fire(); RaycastHit hit; if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range)) { Debug.Log(hit.transform.name); SimpleAIController target = hit.transform.GetComponent <SimpleAIController>(); if (target != null) { target.TakeDamage(damage); } GameObject impactGo = Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal)); Destroy(impactGo, 0.5f); } }