| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Meteorite : MonoBehaviour
- {
- private AttackController ac;
- private Character owner;
- private Vector3 attackDir;
- private Rigidbody rb;
- public float speed;
- public int baseDamage;
- private int damage;
- private void Awake()
- {
- rb = GetComponent<Rigidbody>();
- ac = GetComponent<AttackController>();
- }
- public void Init(Vector3 targetPos,Character _owner)
- {
- owner = _owner;
- transform.position = CalculateSpawnPosition(targetPos);
- rb.velocity = speed * attackDir;
- damage = baseDamage + (int)((0.1f * GameManager.instance.armor + GameManager.instance.myTreasuresTag[3]) * baseDamage);
- }
- private void OnTriggerEnter(Collider other)
- {
- BeHitTrigger target = other.GetComponent<BeHitTrigger>();
- if (target != null)
- {
- if(target.owner is Enemy)
- {
- target.BeHit(ac.attackMethod_summon[0], owner);
- }
- }
- if (other.CompareTag("Ground"))
- {
- gameObject.SetActive(false);
- }
- }
- private Vector3 CalculateSpawnPosition(Vector3 targetPos)
- {
- float randomOffsetX = Random.Range(-8,8);
- Vector3 spawnPos = new Vector3(targetPos.x + randomOffsetX, /*Camera.main.ScreenToWorldPoint(new Vector3(0f, Screen.height)).y*/ targetPos.y + 15f, 0);
- attackDir = (targetPos - spawnPos).normalized;
- return spawnPos;
- }
- }
|