滚动的小球

滚动的小球


1.导入素材包(若素材包不可用可以自己造出需要的小球和方块)并新建需要的平面等物体。
2.编写脚本,有关摄像机的脚本要能移动、发射小球,小球发射后有存在时间,还要制造方块堆,让它处在平面上。
3.最后运行一下检查是否有错误存在。


using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class cubeMove : MonoBehaviour {
    public float moveSpeed = 0.5f;
    private float h, v;
    private Vector3 direction;
	// Use this for initialization
	void Start () {
        h = Time.deltaTime * (-moveSpeed);
        v = 0;
        direction = new Vector3(h, 0, v);
	}

    // Update is called once per frame
    void Update()
    {
        float h = Input.GetAxis("Horizontal") * Time.deltaTime * moveSpeed;
         float v = Input.GetAxis("Vertical") * Time.deltaTime * moveSpeed;
        Vector3 direction = new Vector3(h, 0, v);
        this.GetComponent<Transform>().Translate(direction);  

        /*if (Input.GetMouseButtonDown(0))
        {
            h = Time.deltaTime * (-moveSpeed);
        }
        else if (Input.GetMouseButtonDown(1))
        {
            h = Time.deltaTime * moveSpeed;
        }
        v = Input.GetAxis("Vertical") * Time.deltaTime * moveSpeed;

        if (Input.GetKeyDown(KeyCode.LeftArrow))
        {
            h = -moveSpeed;
            v = 0;
        }
        else if (Input.GetKeyDown(KeyCode.RightArrow))
        {
            h = moveSpeed;
            v = 0;
        }
        else if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            h = 0;
            v = moveSpeed;
        }
        else if (Input.GetKeyDown(KeyCode.DownArrow))
        {
            h = 0;
            v = -moveSpeed;
        }
        else
        {
            v = 0;
            h = 0;
        }*/
        direction = new Vector3(h, 0, v);
        this.GetComponent<Transform>().Translate(direction);


      }
     }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值