void Awake() { originalPosition = new Vector3(transform.position.x, transform.position.y, transform.position.z); originalRotation = transform.rotation; originalScale = transform.localScale; meshRenderer = GetComponent <MeshRenderer>(); attachedCollider = GetComponent <Collider>(); attachedRigidBody = GetComponent <Rigidbody>(); poly3DScript = GetComponent <PolyExplosionThreeDimensional>(); attachedObstacle = GetComponent <NavMeshObstacle>(); }
private void CheckTarget() { RaycastHit hitInfo; // Boss shield layer if (targetLayer == 9 && Physics.Raycast(transform.position, Direction, out hitInfo, maxLength, 1 << 16, QueryTriggerInteraction.Collide)) { GenerateRay(hitInfo.point); BossShield shield = hitInfo.transform.GetComponent <BossShield>(); if (shield != null) { shield.CreateEnemyRay(hitInfo.point, Direction); } } else if (Physics.Raycast(transform.position, Direction, out hitInfo, maxLength, 1 << targetLayer)) { GenerateRay(hitInfo.point); } else if (Physics.Raycast(transform.position, Direction, out hitInfo, maxLength, 1 << 10)) { GenerateRay(hitInfo.point); // Check for destructible item PolyExplosionThreeDimensional destructible = hitInfo.transform.gameObject.GetComponent <PolyExplosionThreeDimensional>(); if (destructible != null) { destructible.DecrementHealth(Damage); SpawnDeathParticle(hitInfo.transform.position); } } else { float distanceOffset = UnityEngine.Random.Range(0f, lengthOffset); //Define first an last point. GenerateRay(transform.position + Direction * (maxLength + distanceOffset)); } // Check if the hit-object can take damage if (hitInfo.transform != null && hitInfo.transform.gameObject.GetComponent <MonoBehaviour>() is IDamageable) { try { (hitInfo.transform.gameObject.GetComponent <MonoBehaviour>() as IDamageable).TakeDamage(Damage, this.OwnerScript); } catch (Exception e) { Debug.Log("<color='ff0000'>[PerlinRay]: Hit info IDamageable error.</color>\n" + e.ToString()); } SpawnDeathParticle(hitInfo.transform.position); } }