Commit 6388d74e authored by czy's avatar czy

用食物个数控制准确控制过桥

parent 860fc557
This diff is collapsed.
This diff is collapsed.
......@@ -23,7 +23,7 @@ public class BossAttackDamageRange : MonoBehaviour
if (other.tag == "Player")
{
other.gameObject.GetComponentInChildren<PlayerMove>().Hurt(0.5f);
other.gameObject.GetComponentInChildren<PlayerMove>().Hurt(1);
ps = Instantiate(hitEffects, hitPos, transform.rotation);
ps.gameObject.AddComponent<DestroyMySel>();
Handheld.Vibrate();//手机震动
......@@ -31,7 +31,7 @@ public class BossAttackDamageRange : MonoBehaviour
}
else if (other.tag == "Competitor")
{
other.gameObject.GetComponentInChildren<AIMove>().Hurt(0.5f);
other.gameObject.GetComponentInChildren<AIMove>().Hurt(1);
ps = Instantiate(hitEffects, hitPos, transform.rotation);
ps.gameObject.AddComponent<DestroyMySel>();
//Handheld.Vibrate();//手机震动
......
......@@ -53,7 +53,7 @@ public class AttackTrigger : MonoBehaviour
//print(other.name+"受到伤害:");
if (other.tag == "Player")
{
other.gameObject.GetComponentInChildren<PlayerMove>().Hurt(0.5f);
other.gameObject.GetComponentInChildren<PlayerMove>().Hurt(1);
ps= Instantiate(hitEffects, hitPos.transform.position, hitPos.transform.rotation);
ps.gameObject.AddComponent<DestroyMySel>();
//Handheld.Vibrate();//手机震动
......@@ -61,7 +61,7 @@ public class AttackTrigger : MonoBehaviour
}
else if (other.tag == "Competitor")
{
other.gameObject.GetComponentInChildren<AIMove>().Hurt(0.5f);
other.gameObject.GetComponentInChildren<AIMove>().Hurt(1);
ps=Instantiate(hitEffects, hitPos.transform.position, hitPos.transform.rotation);
ps.gameObject.AddComponent<DestroyMySel>();
if (Root.tag == "Player")
......
using System.Collections;
using System.Collections.Generic;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
using DG.Tweening.Core;
using HedgehogTeam.EasyTouch;
using TMPro;
using System;
public class PlayerMove : MonoBehaviour
......@@ -61,7 +55,7 @@ public class PlayerMove : MonoBehaviour
public GameObject topPOS;
public int Count = 0;
// Start is called before the first frame update
......@@ -79,28 +73,39 @@ public class PlayerMove : MonoBehaviour
private void OnTriggerEnter(Collider other)
{
//print("OnTriggerEnter:"+other.tag+"--"+other.name);
if (other.tag == "Food")
{
//print("吃到食物。");
Handheld.Vibrate();//手机震动
UpdateScore(1);
if (scale >= (1 + MaxFood * addScale))
if (CurrentFood >= MaxFood)
{
scale = 1 + MaxFood * addScale;
CurrentFood = MaxFood;
}
else
{
scale += addScale;
//进行食物累计和缩放模型。
AddIsPlayChangeModeEffect();
CurrentFood++;
scale = 1 + CurrentFood * addScale;
ChangeAnimationscaleState(scale);
switch (CurrentFood)
{
case 5:
case 10:
case 15:
case 20:
Scale(scale, scale, scale);
ParticleSystem ps = Instantiate(changeModeEffect, transform.position, transform.rotation);
ps.gameObject.AddComponent<DestroyMySel>();
break;
default:
break;
}
}
ChangeAnimationscaleState(scale);
Destroy(other.gameObject);
}
//print("1111" + other.gameObject.tag + "+" + other.gameObject.name);
}
public void UpdateScore(int addNumber)
{
......@@ -112,66 +117,73 @@ public class PlayerMove : MonoBehaviour
private void OnControllerColliderHit(ControllerColliderHit hit)
{
if (hit.gameObject== targetWall)
if (hit.gameObject == targetWall)
{
//print("Player碰到墙:"+ scale);
if (scale>1)
if (CurrentFood >=1)
{
//print("推墙");
hit.gameObject.GetComponent<Rigidbody>().AddForce(new Vector3(0, 0, 100));
scale -= reduceStep;
ReduceIsPlayChangeModeEffect("PushWall");
int aa=hit.gameObject.GetComponent<Wall>().MakeWallMove();
Count += aa;
CurrentFood -= aa;
//Debug.LogError("CurrentFood:" + CurrentFood+"aa:"+aa);
scale -= aa*addScale;
switch (CurrentFood)
{
case 0:
Scale(scale, scale, scale);
break;
case 5:
case 10:
case 15:
case 20:
Scale(scale, scale, scale);
ParticleSystem ps = Instantiate(changeModeEffect, transform.position, transform.rotation);
ps.gameObject.AddComponent<DestroyMySel>();
break;
default:
break;
}
}
else
{
scale = 1;
CurrentFood = 0;
}
ChangeAnimationscaleState(scale);
}
//print("22222"+hit.gameObject.tag+"+"+hit.gameObject.name);
}
//受到伤害
public void Hurt(float hurt)
public void Hurt(int hurt)
{
//进行判断是否播放特效
scale -= hurt;
if (scale < 1)
CurrentFood -= hurt;
if (CurrentFood <= 0)
{
CurrentFood = 0;
scale = 1;
RefreshVertigo(hurt);
RefreshVertigo(1);
}
ChangeAnimationscaleState(scale);
ReduceIsPlayChangeModeEffect("Hurt");
}
//食物增加时,判断是否播放改变模型特效
public void AddIsPlayChangeModeEffect()
{
CurrentFood++;
if (CurrentFood == 5 || CurrentFood == 10 || CurrentFood == 15 || CurrentFood == 20)
{
Scale(scale, scale, scale);
ParticleSystem ps = Instantiate(changeModeEffect, transform.position, transform.rotation);
ps.gameObject.AddComponent<DestroyMySel>();
}
}
/// <summary>
/// 减少时,判断是否播放改变模型特效
/// </summary>
public void ReduceIsPlayChangeModeEffect(string type)
{
int tempFood = CurrentFood;
CurrentFood = (int)((scale - 1.0f) / addScale);
if (tempFood != CurrentFood && (CurrentFood == 0||CurrentFood == 5 || CurrentFood == 10 || CurrentFood == 15 || CurrentFood == 20))
switch (CurrentFood)
{
Scale(scale, scale, scale);
ParticleSystem ps = Instantiate(changeModeEffect, transform.position, transform.rotation);
ps.gameObject.AddComponent<DestroyMySel>();
if (type == "Hurt")
{
case 0:
Scale(scale, scale, scale);
break;
case 5:
case 10:
case 15:
case 20:
Scale(scale, scale, scale);
ParticleSystem ps = Instantiate(changeModeEffect, transform.position, transform.rotation);
ps.gameObject.AddComponent<DestroyMySel>();
GenerateRandomFoodAroundPos(5, transform.position, 5);//生成5个食物距离为5
}
break;
default:
break;
}
}
......@@ -435,6 +447,7 @@ public class PlayerMove : MonoBehaviour
/// <param name="radius"></param>
public void GenerateRandomFoodAroundPos(int number, Vector3 targetPos,float radius)
{
float randomAngle = UnityEngine.Random.Range(0, 360);
//return;
for (int i = 0; i < number; i++)
{
......@@ -452,7 +465,7 @@ public class PlayerMove : MonoBehaviour
go.tag = "Untagged";
go.GetComponent<Food>().isUnNomalFood = true;
//rig.AddForce(Quaternion.Euler(new Vector3(UnityEngine.Random.Range(-80, -20), UnityEngine.Random.Range(0, 360), 0)) * Vector3.forward * Force);
rig.AddForce(Quaternion.Euler(new Vector3(-45, i*360.0f/number,0)) * Vector3.forward * Force);
rig.AddForce(Quaternion.Euler(new Vector3(-45, randomAngle+i * 360.0f/number,0)) * Vector3.forward * Force);
}
}
......
......@@ -4,18 +4,32 @@ using UnityEngine;
public class Wall : MonoBehaviour
{
//public AttackTrigger target;
public ParticleSystem ps;
[Header("改变模型特效")]
public ParticleSystem changeModelEffect;
[Header("墙的移动")]
public GameObject targetPath;
public int stepNumberToEnd = 30;
public bool isMove = false;
public bool isMoveComplete = true;
public float Speed = 10;
public float pathLength;
public float stepLength;
public Vector3 tempBeginPos;
public Vector3 targetPos;
void Start()
{
pathLength = targetPath.GetComponent<Collider>().bounds.size.z;
stepLength = pathLength / stepNumberToEnd;
tempBeginPos = transform.position;
targetPos = transform.position + new Vector3(0, 0, stepLength);
}
private void OnTriggerEnter(Collider other)
{
if (other.name == "PathEndTrigger")
{
ParticleSystem particleSystem= Instantiate(ps, transform.position+new Vector3(0,2,0), transform.rotation);
ParticleSystem particleSystem= Instantiate(changeModelEffect, transform.position+new Vector3(0,2,0), transform.rotation);
particleSystem.gameObject.AddComponent<DestroyMySel>();
particleSystem.transform.localScale = new Vector3(2,2,2);
particleSystem.Play();
......@@ -26,6 +40,49 @@ public class Wall : MonoBehaviour
void Update()
{
if (isMove == false)
{
tempBeginPos = transform.position;
targetPos = transform.position + new Vector3(0, 0, stepLength);
isMoveComplete = true;
}
else
{
//均速移动一定的距离
if (targetPos.z-transform.position.z >Speed/20.0) //速度太快会有问题。
{
isMoveComplete = false;
//transform.position = Vector3.Lerp(tempBeginPos, targetPos, timer/stepLengthCoseTime);
transform.position +=(targetPos - tempBeginPos) * Time.deltaTime*1/(stepLength/Speed);
}else
{
isMove = false;
isMoveComplete = true;
transform.position = targetPos;
tempBeginPos = transform.position;
targetPos = transform.position + new Vector3(0, 0, stepLength);
}
}
}
public void Move()
{
}
public int MakeWallMove()
{
if (!isMoveComplete) {
//墙还在移动中
return 0;
}
else
{
//墙静止
isMove = true;
isMoveComplete = false;
return 1;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment