Commit 5df3f12e authored by czy's avatar czy

镜头优化和攻击

parent 11fd03c6
......@@ -229,6 +229,12 @@ AnimatorController:
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 0}
- m_Name: Grounded
m_Type: 4
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 0}
m_AnimatorLayers:
- serializedVersion: 5
m_Name: Base Layer
......
This diff is collapsed.
......@@ -78,6 +78,7 @@ public class AIMove : MonoBehaviour
Destroy(other.gameObject);
}
}
private void Scale(float x, float y, float z)
{
transform.localScale = new Vector3(x, y, x);
......@@ -98,12 +99,22 @@ public class AIMove : MonoBehaviour
RandomFoodNumberToPush = Random.Range(1,11);
HaveFoodNumber = 0;
//targetObj = GetTargetPos();
//print("改变状态为回到起点2");
aiState = AIState.TurnBackToPathPos0; //到路径起点,准备去找食物
}
Scale(power, power, power);
}
}
//受到伤害
public void Hurt(float hurt)
{
power -= hurt;
if (power < 1)
{
power = 1;
}
Scale(power, power, power);
}
private void FixedUpdate()
{
......@@ -125,13 +136,13 @@ public class AIMove : MonoBehaviour
}
//------------------------AI的寻路点切换---------------------------------------------------------------
switch (aiState)
{
case AIState.FindFood:
//找食物
if (targetObj == null || targetObj.tag!= "Food")
{
targetObj = GetTargetPos();
//print("获取新目标:"+ targetObj);
}
......@@ -139,7 +150,7 @@ public class AIMove : MonoBehaviour
case AIState.GoToPathPos0:
//去路径起点
targetObj = pathPos0;
if (Vector3.Distance(transform.position, pathPos0.transform.position) < 0.2f)
if (Vector3.Distance(transform.position, pathPos0.transform.position) < 1.2f)
{
aiState = AIState.Push;
}
......@@ -150,6 +161,7 @@ public class AIMove : MonoBehaviour
{
//按路径返回
targetObj = pathPos0;
//print("改变状态为回到起点1");
aiState = AIState.TurnBackToPathPos0;
}
else
......@@ -160,9 +172,12 @@ public class AIMove : MonoBehaviour
case AIState.TurnBackToPathPos0:
//返回路径起点
targetObj = pathPos0;
if (Vector3.Distance(transform.position, pathPos0.transform.position) < 0.2f)
if (Vector3.Distance(transform.position, pathPos0.transform.position) < 1.2f)
{
//print("改变状态为寻找食物。");
aiState = AIState.FindFood;
targetObj = GetTargetPos();
//print("获取新目标:" + targetObj);
}
break;
default:
......@@ -171,7 +186,7 @@ public class AIMove : MonoBehaviour
}
//-------------------------------------------------------------------------------------
//print(aiState+""+targetObj);
//print("aiState:" + aiState+ "-targetObj:" + targetObj+" 距离:"+ Vector3.Distance(transform.position, pathPos0.transform.position));
yDelta = SpeedY * Time.deltaTime;
Vector3 speed=( targetObj.transform.position - transform.position).normalized*VSpeed;
......@@ -180,6 +195,7 @@ public class AIMove : MonoBehaviour
Move();
}
......
......@@ -14,14 +14,16 @@ public class Attack : MonoBehaviour
// Update is called once per frame
void Update()
{
//gameObject.transform.parent.GetComponentInChildren<AttackTrigger>().isCauseDamage = false;
}
public void AttackLeft()
{
//print(gameObject.name+":左手攻击");
gameObject.transform.parent.GetComponentInChildren<AttackTrigger>().isCauseDamage = true ;
}
public void AttackRight()
{
//print(gameObject.name + ":右手攻击");
gameObject.transform.parent.GetComponentInChildren<AttackTrigger>().isCauseDamage = true;
}
}
......@@ -7,7 +7,8 @@ public class AttackTrigger : MonoBehaviour
public Animator animator;
public string OtherTag= "Competitor";
public GameObject targetWall;
//伤害帧
public bool isCauseDamage=false;
void Start()
{
......@@ -16,7 +17,7 @@ public class AttackTrigger : MonoBehaviour
// Update is called once per frame
void Update()
{
isCauseDamage = false;//由帧事件改变该值
}
private void OnTriggerEnter(Collider other)
{
......@@ -31,6 +32,21 @@ public class AttackTrigger : MonoBehaviour
}
}
private void OnTriggerStay(Collider other)
{
if (other.tag == OtherTag&&isCauseDamage)
{
//print(other.name+"受到伤害:");
if (other.tag == "Player")
{
other.gameObject.GetComponentInChildren<PlayerMove>().Hurt(0.5f);
}
else if (other.tag == "Competitor")
{
other.gameObject.GetComponentInChildren<AIMove>().Hurt(0.5f);
}
}
}
private void OnTriggerExit(Collider other)
{
......
......@@ -20,32 +20,13 @@ public class PlayerMove : MonoBehaviour
public float HSpeed = 10.0f;
[Tooltip("游戏结束每秒减少的速度")]
public float deceleration = 15;
[Header("特效")]
public ParticleSystem particleChange; //变身特效
public float power = 1;
private RaycastHit RHit;
private CharacterController characterController;
private bool m_bIsCanMove = true;//是否能开车
private MeshCollider[] m_targetTrans;//所有目标
private MeshCollider m_curTargetTrans;//当前抓的目标
// private Rigidbody m_rigidBody;//自身刚体
private Dictionary<MeshCollider, bool> m_dicBox = new Dictionary<MeshCollider, bool>();
private bool m_bControlStartMove = false;
private RectTransform m_thumbRT;//摇杆
private Dictionary<Rigidbody, bool> m_dicRigidDic = new Dictionary<Rigidbody, bool>();
private bool isGround1 = true;
private bool isGround2 = true;
private float timer = 0.0f;
//输入控制player移动的中间变量
private float _vertSpeed = 0.0f;
private float xDelta=0.0f;
......@@ -60,30 +41,20 @@ public class PlayerMove : MonoBehaviour
[HideInInspector]
public float MoveSpeed=0.0f;
private bool Grounded = false;
//最大速度等级
private int MaxSpeedLevel = 15;//1-15 分为 1-5 6-10 11-15
public GameObject targetWall;
public GameObject children;
// Start is called before the first frame update
void Start()
{
//从配置文件ConfigurationFile中获取数据
//VSpeed = ConfigurationFile.instance.VSpeed;
SpeedLevel = ConfigurationFile.instance.SpeedLevel;
//AddSpeed = ConfigurationFile.instance.AddSpeed;
//HSpeed = ConfigurationFile.instance.HSpeed;
//摇杆控制
GameServices.inputService.joyStick.onTouchStart.AddListener(OnTouchStart);
GameServices.inputService.joyStick.onTouchUp.AddListener(OnTouchUp);
......@@ -131,6 +102,17 @@ public class PlayerMove : MonoBehaviour
Scale(power, power, power);
}
}
//受到伤害
public void Hurt(float hurt)
{
power -= hurt;
if (power < 1)
{
power = 1;
}
Scale(power, power, power);
}
private void Scale(float x,float y,float z)
{
transform.localScale = new Vector3(x,y,x);
......@@ -256,7 +238,7 @@ public class PlayerMove : MonoBehaviour
}
}
if (m_bIsCanMove && !BattleCtrl.instance.IsScoreSettlementStatus)
if ( !BattleCtrl.instance.IsScoreSettlementStatus)
{
//print("控制摇杆");
if (timerVertigo <= 0)
......@@ -340,7 +322,9 @@ public class PlayerMove : MonoBehaviour
{
angle = -Mathf.Abs(angle);
}
transform.localEulerAngles = new Vector3(0, angle, 0);
//transform.localEulerAngles = new Vector3(0, angle, 0);
children.transform.localEulerAngles = new Vector3(0, angle, 0);
//transform.rotation = Quaternion.Euler(0, angle, 0);//转向
characterController.Move(new Vector3(xDelta, yDelta, zDelta));//移动
}
......
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