3D弹球

单机版3D弹球,哈哈哈哈哈,回忆起当年的笨拙之作,今天突然被勾引出兴趣,突然特别想玩这个游戏,就自己写一个,发一下,哈哈哈

随便创建个项目,粘进去就能玩

重点是球的物理系统要调一下,摩擦力与摩擦系数,同时要锁定一下Y轴,以免弹飞,我的系数跳的有点小,导致球的弹性看起来特别好,如果有谁想玩铅球类型的,可以自己尝试更改

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using XLua;
using UnityEngine.UI;
using System.IO;

namespace Tools
{
    [LuaCallCSharp]
    public class Load
    {
        public static Sprite LoadSprite(string name)
        {
            return Resources.Load<Sprite>(name);
        }
    }
    [LuaCallCSharp]
    class ActionCalls
    {
        public static void GameObjectAddListener(LuaFunction func, GameObject btn, GameObject field)
        {
            Button button = btn.GetComponent<Button>();
            button.onClick.AddListener(delegate ()
            {
                func.Call(field);

            });
        }
        public static bool RayFunction(Ray ray, out RaycastHit hit, int len, int layermask)
        {
            return Physics.Raycast(ray, out hit, len, 1 << layermask);
        }

        public static void WriteJson()
        {

        }

        private byte[] ResetPath(ref string filepath)
        {
            filepath = filepath.Replace(".", "/");
            string luapath = Application.dataPath + "/lua/" + filepath + ".lua";
            string strLuaContent = File.ReadAllText(luapath);
            byte[] res = System.Text.Encoding.UTF8.GetBytes(strLuaContent);
            return res;
        }

    }

}


using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using XLua;
using System.IO;
public class SingleEntry
{
    static LuaEnv entry;
    public static LuaEnv GetEntry
    {
        get
        {
            if (entry == null)
            {
                entry = new LuaEnv();
                entry.AddLoader(LuaRes);
            }
            return entry;
        }
    }

    //改变文件后缀
    private static byte[] LuaRes(ref string filepath)
    {
        filepath = filepath.Replace(".", "/");
        string luapath = Application.dataPath + "/LuaSource/" + filepath + ".lua";
        string strLuaContent = File.ReadAllText(luapath);
        byte[] res = System.Text.Encoding.UTF8.GetBytes(strLuaContent);
        return res;
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using XLua;
using System;
public class Launcher : MonoBehaviour
{
    Action start;
    Action update;
    private void Awake()
    {
        SingleEntry.GetEntry.DoString("require'main'");
    }

    // Start is called before the first frame update
    void Start()
    {
        start = SingleEntry.GetEntry.Global.Get<Action>("start");
        update = SingleEntry.GetEntry.Global.Get<Action>("update");
        start?.Invoke();

    }

    // Update is called once per frame
    void Update()
    {
        update?.Invoke();


    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using XLua;
using UnityEngine.UI;
[CSharpCallLua]
[LuaCallCSharp]
public class BallMana : MonoBehaviour
{
    Text text;
    Action<Collision> enter;
    // Start is called before the first frame update
    void Start()
    {

        enter = SingleEntry.GetEntry.Global.Get<Action<Collision>>("onenter");
        print(enter);
    }

    // Update is called once per frame
    void Update()
    {

    }

    private void OnCollisionEnter(Collision collision)
    {
        //Debug.Log(collision.gameObject.name);
        //Debug.Log(collision.gameObject.tag);
        enter?.Invoke(collision);
    }

    private void OnDestroy()
    {

    }
}

cs = CS.UnityEngine
function start()
    Ball = cs.Resources.Load('Ball')
    Left = cs.GameObject.Find('left')
    Right = cs.GameObject.Find('right')
    Resrote1 = Left.transform.rotation
    Resrote2 = Right.transform.rotation
    ballText = cs.GameObject.Find('balls'):GetComponent('Text')
    scoreText = cs.GameObject.Find('scores'):GetComponent('Text')

    launcher = cs.GameObject.Find('launcher')
    ballinst = nil
    ballcount = 3
    score = 0
    eulerAngle = 0
    eulerAngle2 = 0
end
function update()
    scoreText.text = score
    ballText.text = ballcount

    if ballcount < 0 then
        cs.Time.timeScale = 0
        print('游戏结束')
    end
    x = cs.Input.GetAxis('Horizontal')
    if x ~= 0 then
        launcher.transform.position = launcher.transform.position + cs.Vector3(x, 0, 0)
    end

    if CS.UnityEngine.Input.GetKeyDown(CS.UnityEngine.KeyCode.Space) and ballinst == nil then
        --  launcher.transform.position=cs.Vector3(math.random(-3,3),launcher.transform.position.y,launcher.transform.position.z)
        BornPos = cs.GameObject.Find('bornpos').transform.position
        ballinst = cs.Object.Instantiate(Ball, BornPos, cs.Quaternion.identity)
        ballcount = ballcount - 1
    end
    if cs.Input.GetMouseButton(0) then
        if eulerAngle < 40 then
            Left.transform:RotateAround(Left.transform.position, Left.transform.up, -3)
            eulerAngle = eulerAngle + 3
        end
    end
    if cs.Input.GetMouseButtonUp(0) then
        Left.transform.rotation = Resrote1
        eulerAngle = 0
    -- Left.transform:RotateAround(Left.transform.position,Left.transform.up,40);
    end
    if cs.Input.GetMouseButton(1) then
        if eulerAngle2 < 40 then
            eulerAngle2 = eulerAngle2 + 3
            Right.transform:RotateAround(Right.transform.position, Right.transform.up, 3)
        end
    end
    if cs.Input.GetMouseButtonUp(1) then
        Right.transform.rotation = Resrote2
        eulerAngle2 = 0
    -- Right.transform:RotateAround(Right.transform.position,Right.transform.up,-40)
    end
    if ballinst ~= nil then
        if ballinst.transform.position.y < -15 then
            cs.Object.Destroy(ballinst)
            ballinst = nil
        end
    end
end

function onenter(collision)
    tag = collision.gameObject.tag
    if tag == '10' then
        score = score + 10
    end
    if tag == '100' then
        score = score + 100
    end
    if tag == '1000' then
        score = score + 1000
    end
    if tag == '500' then
        score = score + 500
    end
    print(collision.gameObject.name)
    if collision.gameObject.name == 'lefthand' or collision.gameObject.name == 'righthand' then
        if ballinst then
            ballinst:GetComponent('Rigidbody'):AddForce(cs.Vector3.up * 700)
        end
    end
end

CollisionBase = {
    score = 0
}
CollisionBase.__index = CollisionBase
FirstCollision = {}

setmetatable(FirstCollision, CollisionBase)

function FirstCollision:SetScore(scorevalue)
    local temp = {}
    temp.score = scorevalue
    setmetatable(temp, FirstCollision)
    return temp
end

在这里插入图片描述
最上边那个方块是发射口,可移动的,
在这里插入图片描述

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值