1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Player : 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().bulletG);
- go.name = GameController.GetInstance().bulletG.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);
- //transform.rotation = rotation;
- this.gs.CreateRay(poi, rotation, 1);
- }
- }
- 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();
- }
- }
|