void ShoutOut() { if (hit_sphere.activeSelf) { hit_sphere.SetActive(false); InAttackRange(); } if (kinds != ArrowsKind.normal) { box.enabled = false; } controll.islunch = true; temp = Vector3.Distance(leftrain.transform.position, rightrain.transform.position); //Debug.Log(bstatus.ToString() + "<<<<<<<<<<<<"); if (rb != null) { rb.mass = 0.2f; rb.angularDrag = 0; rb.freezeRotation = true; switch (kinds) { case ArrowsKind.normal: if (temp < 0.15f) { rb.AddForce(-bullet.transform.up * 10f); } else { rb.AddForce(-bullet.transform.up * 1000f * (temp - 0.15f)); } controll.endpos = arrowstop; break; case ArrowsKind.torch: case ArrowsKind.ice: rb.AddForce(-bullet.transform.up * 1000f); break; default: break; } } else { Debug.Log("withoutrigidbody"); } status = shootstatus.stay; bstatus = bulletstatus.none; kinds = ArrowsKind.normal; fire_status = firestatus.reday; if (fire != null && bullet != null) { fire.transform.SetParent(bullet.transform); } // Destroy(fire, 1f); isfireon = false; /*重置箭头火焰是否点着*/ }
void Awake() { kinds = ArrowsKind.normal; status = shootstatus.none; bstatus = bulletstatus.none; fire_status = firestatus.reday; mask = LayerMask.GetMask("Floor"); }
void Choiseparent(GameObject parent, bool key) { if (Vector3.Distance(parent.transform.position, bowstring.transform.position) < 0.2f && key) { //引入缓冲池 if (msg.ai_pool.ContainsKey(5) && msg.ai_pool[5].Count > 0) { bullet = msg.ai_pool[5][0]; bullet.SetActive(true); msg.ai_pool[5].Remove(bullet); box = bullet.GetComponent <BoxCollider>(); controll = bullet.GetComponent <Bulletcontroll>(); //Debug.Log("ifififiiffi"); } else { bullet = GameObject.Instantiate(msg.bulletprefab) as GameObject; box = bullet.AddComponent <BoxCollider>(); controll = bullet.AddComponent <Bulletcontroll>(); //Debug.Log("ekseelseelse"); } if (bullet.GetComponent <Rigidbody>() != null) { rb = bullet.GetComponent <Rigidbody>(); } else { rb = bullet.AddComponent <Rigidbody>(); } bullet.tag = "PlayerBullet"; box.enabled = true; // box.isTrigger = true; box.size = new Vector3(0.2f, 1f, 0.1f); box.center = new Vector3(0f, -0.5f, 0f); // box.isTrigger = true; arrows = bullet.transform.FindChild("jian").gameObject; controll.msg = msg; controll.pcontroll = this; controll.islunch = false; controll.istrial = false; controll.ishit = false; controll.isset = false; rb.useGravity = true; controll.rb = rb; controll.timer = 0f;/*重置计时器*/ controll.stoptimer = 0f; controll.isaddtopool = false; rb.isKinematic = true; bullet.transform.SetParent(parent.transform); bullet.transform.localPosition = Vector3.zero; bullet.transform.localScale = Vector3.one; bullet.transform.localRotation = Quaternion.identity; bstatus = bulletstatus.ready; } }
void CreatArrows() { //调整箭的方向,箭的旋转,发射出去的就不管了 Vector3 tempforward = Vector3.one; if (bullet != null && handfirst == rightrain && !bullet.GetComponent <Bulletcontroll>().islunch) { bullet.transform.up = Vector3.Normalize(leftrain.transform.position - bow.transform.position); tempforward = -bullet.transform.up; // Debug.DrawLine(target.transform.position, leftrain.transform.position, Color.red); // arrows.transform.localEulerAngles = new Vector3(0, leftrain.transform.eulerAngles.y, -90); } else if (bullet != null && handfirst == leftrain && !bullet.GetComponent <Bulletcontroll>().islunch) { bullet.transform.up = Vector3.Normalize(rightrain.transform.position - bow.transform.position); tempforward = -bullet.transform.up; // Debug.DrawLine(target.transform.position, rightrain.transform.position, Color.red); // arrows.transform.localEulerAngles = new Vector3(0, rightrain.transform.eulerAngles.y, -90); } //判断哪只手柄拿着弓 if (handfirst.Equals(leftrain)) { if (bstatus == bulletstatus.none) { Choiseparent(rightrain, msg.Rightkey); } if (msg.Rightkey && bstatus == bulletstatus.ready) { Vector3 tempvec = Vector3.Normalize(leftrain.transform.position - rightrain.transform.position); float limitshaking = Vector3.Distance(leftrain.transform.position, rightrain.transform.position); if (limitshaking > 0.15f) { if (limitshaking * 10 % 2f <= 0.4f) { //Debug.Log("11111111111"); RainsShaking(SteamVR_Controller.DeviceRelation.Rightmost, 3000); RainsShaking(SteamVR_Controller.DeviceRelation.Leftmost, 3000); } } bowstring.transform.position = rightrain.transform.position; AttackRange(tempforward, leftrain); } if (!msg.Rightkey && bstatus == bulletstatus.ready) { bowstring.transform.localPosition = bowsoldpos; bstatus = bulletstatus.lunch; } if (!msg.Rightkey && bstatus == bulletstatus.lunch) { status = shootstatus.shoot; rb.isKinematic = false; bullet.transform.SetParent(null); } } else { if (bstatus == bulletstatus.none) { Choiseparent(leftrain, msg.Leftkey); } if (msg.Leftkey && bstatus == bulletstatus.ready) { float limitshaking = Vector3.Distance(leftrain.transform.position, rightrain.transform.position); // target.transform.LookAt(leftrain.transform.position); if (limitshaking > 0.15f) { //手柄靠近时震动 if (limitshaking < 0.3f) { // RaisShaking(SteamVR_Controller.DeviceRelation.Leftmost, 800); //var deviceIndex2 = SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.Rightmost); //SteamVR_Controller.Input(deviceIndex2).TriggerHapticPulse(800); } if (limitshaking * 10 % 2f <= 0.4f) { RainsShaking(SteamVR_Controller.DeviceRelation.Rightmost, 3000); RainsShaking(SteamVR_Controller.DeviceRelation.Leftmost, 3000); //var deviceIndex2 = SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.Rightmost); //SteamVR_Controller.Input(deviceIndex2).TriggerHapticPulse(800); } } bowstring.transform.position = leftrain.transform.position; AttackRange(tempforward, rightrain); } if (!msg.Leftkey && bstatus == bulletstatus.ready) { bowstring.transform.localPosition = bowsoldpos; bstatus = bulletstatus.lunch; } if (!msg.Leftkey && bstatus == bulletstatus.lunch) { status = shootstatus.shoot; rb.isKinematic = false; bullet.transform.SetParent(null); } } }