// Use this for initialization protected override void Start() { IgnoreCollision();//Ignore all collisions with the same tag attackDistance = attackDistance + (EUtils.GetObjectCollUnitSize(gameObject).z / 2); if (attackDistance <= 0) { attackDistance = 0.1f; } animator = GetComponent <Animator>(); if (animator != null) { animationSpeed = animator.speed; } jumpClip = jumpClips[Random.Range(0, jumpClips.Length)]; base.Start(); }
// Use this for initialization /* * protected override void Start() * { * base.Start(); * } * // Update is called once per frame * protected override void Update() * { * base.Update(); * } */ //drop a banana peel. public void DropPeel() { //ToDo if (peelCount > 0 && !isInBlender) { Vector3 position = transform.position; //Current position RaycastHit hit; //For the raycast hit result //Raycast down from object position if (Physics.Raycast(transform.position, -transform.up, out hit, 10)) { GameObject clone = GameObject.Instantiate(bananaPeel.gameObject, position, transform.rotation) as GameObject; //Drop peel Physics.IgnoreCollision(clone.collider, collider); position.y = hit.point.y + (EUtils.GetObjectCollUnitSize(clone).y / 2); //Change y position to the hitting y position. clone.transform.position = position; Debug.Log((EUtils.GetObjectCollUnitSize(clone).y / 2)); } //Clone prefeb object and place it in the game! peelCount--;//one less peel to drop } }
protected virtual void Attack() //Attack! { RaycastHit[] hit; //Get all objects that we hit bool foundHit = false; //found a target to hit Vector3 castPosition = new Vector3(transform.position.x, transform.position.y + (EUtils.GetObjectCollUnitSize(gameObject).y), transform.position.z); hit = Physics.RaycastAll(castPosition, transform.forward /* * 0.5f*/, attackDistance); //Debug.DrawRay(castPosition, transform.forward * attackDistance, Color.red); // Debug.Log(hit.Length); for (int i = 0; i < hit.Length; i++) { if (hit[i].collider == target.collider) { //http://docs.unity3d.com/ScriptReference/Time-time.html if (Time.time >= nextAttack) //Is it time to attack? { nextAttack = Time.time + attackSpeed; //Set up next attack target.DoDamage(damage); //Do Attack } isInAttackRange = true; foundHit = true; } } if (!foundHit) { isInAttackRange = false; nextAttack = Time.time + attackSpeed; //Setup next attack until we are at our target } }
public AudioClip bulletAudioClip; //Bullet sound /* * // Use this for initialization * protected override void Start() * { * base.Start(); * } * // Update is called once per frame * protected override void Update() * { * base.Update(); * } */ protected override void Attack() { if (isInAttackRange)//Are we in range? { //Object distance //Vector3 targetPosition = new Vector3(target.transform.position.x, transform.position.y, 0); //float distance = Vector3.Distance(transform.position, targetPosition); //is the current distance lower then the attack distance? // Debug.Log(Mathf.Abs(transform.position.x - target.transform.position.x)); //Debug.Log(distance + ":" + attackDistance); //if (distance <= attackDistance) //{ // Debug.Log(Time.time + ":" + nextAttack); //http://docs.unity3d.com/ScriptReference/Time-time.html if (Time.time >= nextAttack) //Is it time to attack? { //Debug.Log("BOOM"); nextAttack = Time.time + attackSpeed; //Set up next attack Vector3 spawnPosition = new Vector3(transform.position.x, transform.position.y + (EUtils.GetObjectCollUnitSize(gameObject).y / 2), transform.position.z); Bullet clone = GameObject.Instantiate(bullet, spawnPosition, transform.rotation) as Bullet; //Clone bullet prefeb SoundManager.Instance.PlaySound(bulletAudioClip, transform.position, SoundManager.SoundTypes.EFFECT, false, transform); //Play Sound at some position with soundtype of Effect not looping and parent of this gameobject. clone.Shoot(damage, target); //The bullet goes torwards the target\ } isInAttackRange = true; //We are in range // } //else //{ //Debug.Log("NOPE.AVI"); //isInAttackRange = false;// Not anymore //nextAttack = Time.time + attackSpeed; //Setup next attack until we are at our target //} //spawn particle } else { //isInAttackRange = false;// Not anymore nextAttack = Time.time + attackSpeed; //Setup next attack until we are at our target } base.Attack(); }