游戏开发之路 二

开发Demo 一

1.角色功能

① 朝着鼠标点击方向转动:(Done)

    Vector3 Move_Player(){
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hitInfo;
 
        if(Physics.Raycast(ray, out hitInfo, 200, whatIsGround)){
            Vector3 target = hitInfo.point;
            target.y = transform.position.y;
            transform.LookAt(target);
            return target;
        }
        else
        {
            Debug.Log("error");
            return Vector3.zero;
        }
    }

②角色射击:(Done)

void Fire()
    {
        Vector3 shutdir;
        if (Input.GetMouseButtonDown(0))
        {
            bullet = (GameObject) Instantiate(Gamemanager.instance.bullet.bulletprefab,
                transform.GetChild(0).position, Quaternion.identity);
            shutdir = (Move_Player()-transform.position).normalized;
            bullet.transform.GetComponent<Shut>().ShutDir = shutdir;
        }
    }

③角色对Enemy造成伤害:(Done)

private void OnTriggerEnter(Collider other)
    {
        DamageData data=new DamageData();
        if (other.tag=="Enemy")
        {
            data.damage = Gamemanager.instance.bullet.Damage;
            get_hit_able getHitAble=transform.GetComponent<get_hit_able>();//get_hit_able 是否可以受伤的一个脚本
            if(getHitAble==null)return;
            getHitAble.OnDamage(data);
        }
        
    }

get_hit_able(//可以受伤脚本):(待完善)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
using System;
public class DamageData
{
    public float damage;
}
[Serializable]
public class Damage_Events:UnityEvent<get_hit_able,DamageData>{}
public class get_hit_able : MonoBehaviour
{
    
    public Text Hp_text;
    public Slider slider;
    private float Reset_Time;
    public float MaxHp;
    public float Hp;   
    public float UnAttack_state_time;
    public bool UnAttack_state=false;
    private float In_UnAttack_state_time=0;
    public Damage_Events On_Damage; 
    public Damage_Events On_Death;
    public Damage_Events On_Reset;
    // Start is called before the first frame update
    void Start()
    {
        slider.maxValue=MaxHp;
        Hp=MaxHp;
        slider.value=Hp;
        Reset_Time=2*Time.deltaTime;
    }

    // Update is called once per frame
    void Update()
    {
        UnAttacked();
        
    }
    public void OnReset(){
            Hp=MaxHp;
            UnAttack_state=false;
            In_UnAttack_state_time=0;
            
    }
    public void OnDamage(DamageData data){
        if(Hp<=0||UnAttack_state)return;
        
        Debug.LogWarning("减少"+data.damage+"滴血");
        Hp-=data.damage;
        Hp_text.text=Hp.ToString();
        slider.value=Hp;
        if(Hp<=0){
            //死亡
            On_Death?.Invoke(this,data);
            On_Reset?.Invoke(this,null);
            // Reset();
        }
        else{
            //受伤
            On_Damage?.Invoke(this,data);
        }
        
    }
    public void UnAttacked(){
        if(UnAttack_state){
            In_UnAttack_state_time+=Time.deltaTime;
            if(In_UnAttack_state_time>=UnAttack_state_time)
            {
                UnAttack_state=false;
                In_UnAttack_state_time=0;
            }
        }
    
                
    }
    
    
    // private void Reset()
    // {
    //     Debug.LogWarning("重置");
    //     if(Reset_Time<=Time.deltaTime){
    //         Hp=MaxHp;
    //         UnAttack_state=false;
    //         In_UnAttack_state_time=0;
    //     }
        
    // }
}

④敌人AI移动:(Done)

if(Vector3.Distance(Target.position,transform.position)>=Attack_Area)
        {
            _navMeshAgent.SetDestination(Target.position);
            transform.LookAt(Target.position); 
        }
        else
        {
            if(State!="Attack")
            animator.SetTrigger("Attack");
            // State="Attack";
            // }
        }

⑤角色和敌人受伤:(待完成)

⑥角色和敌人动画播放:(待完成)

⑦敌人随机生成:(待完成)

⑧游戏环境美化:(待完成)

⑨关卡和玩法设计:(待完成)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值