123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Moster : MonoBehaviour {
- private GameObject _bulletPos;
- // public GameObject prefab;
- private GameObject go;
- private Bullet gs;
- // Use this for initialization
- void Awake()
- {
- this._bulletPos = transform.Find("GunPos").GetChild(0).GetChild(0).Find("bulletPos").gameObject;
- }
- void Start()
- {
- _ray = new Ray();
- // this.CreateRay();
- }
- // Update is called once per frame
- void Update()
- {
- }
- Ray _ray;
- RaycastHit _hit;
- void CreateRay()
- {
- var forw = this.transform.forward;
- this._ray.origin = this._bulletPos.transform.position;
- this._ray.direction = forw;
- if (!this.go)
- {
- this.go = GameObject.Instantiate(GameController.GetInstance().bulletR);
- go.name = GameController.GetInstance().bulletR.name;
- go.transform.SetParent(GameController.GetInstance().Bullet);
- this.gs = this.go.AddComponent<Bullet>();
- }
- this.go.transform.position = this._bulletPos.transform.position;
- this.go.transform.rotation = this.transform.rotation;
- if (Physics.Raycast(_ray, out _hit))
- {
- var poi = _hit.point;
- var dis = Vector3.Distance(this._bulletPos.transform.position, poi);
- var scale = this.go.transform.localScale;
- this.go.transform.localScale = new Vector3(scale.x, scale.y, dis);
- var tag = this._hit.collider.tag;
- if (tag == "player" || tag == "moster")
- {
- this.gs.SetNextNotActive();
- }
- else
- {
- var nor = this._hit.normal;
- Vector3 curDir = transform.TransformDirection(Vector3.forward);
- var newDir = Vector3.Reflect(curDir, nor);
- Quaternion rotation = Quaternion.FromToRotation(Vector3.forward, newDir);
- this.gs.CreateRay(poi, rotation, 2);
- }
- }
- else
- {
- var scale = this.go.transform.localScale;
- this.go.transform.localScale = new Vector3(scale.x, scale.y, 100);
- this.gs.SetNextNotActive();
- }
- }
- public void RotationSelf(float rota)
- {
- transform.Rotate(Vector3.up, rota);
- this.CreateRay();
- }
- }
|