Breakout Clone 打砖块
如果不想要天空做为背景(更改)
更改地面材质
1.金属属性(1 像金属)
2.光滑度(0-1 纸 最光滑反光)
代码怎么实例化子弹(小球)
发射小球和相机重合
void Start () {
GameObject.Instantiate(bullet, transform.position, transform.rotation);
//(小球,相机位置,相机旋转)此时小球和相机重合
}
控制子弹的生成
void Update () {
if (Input.GetMouseButtonDown(0))
//判断鼠标键的按下 0是左键
{
GameObject.Instantiate(bullet, transform.position, transform.rotation);
//实例化子弹
}
}
按鼠标左键3下生成了 3 个小球
给子弹施加初速度
为相机增添一个Shoot(C#)
using UnityEngine;
using System.Collections;
public class Shoot : MonoBehaviour {
public GameObject bullet;
public float speed = 5;
// Use this for initialization
void Start () {
//GameObject.Instantiate(bullet, transform.position, transform.rotation);
//实例化
//(小球,相机位置,相机旋转)此时小球和相机重合
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButtonDown(0)) //判断鼠标键的按下 0是左键
{
GameObject b = (GameObject)GameObject.Instantiate(bullet, transform.position, transform.rotation);
//实例化得到返回值
Rigidbody rgd = b.GetComponent<Rigidbody>();
//得游戏物体钢体组件
rgd.velocity = transform.forward * speed;
// 施加速度 相机前方向(0,0,1)
}
}
}
直线打过去 速度20
这个面板改了速度 以20为准(原先速度为5)
控制相机的左右移动
为相机增添一个Movement(C#)
WSAD
using UnityEngine;
using System.Collections;
public class Movement : MonoBehaviour {
public float speed = 3;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
float h = Input.GetAxis("Horizontal"); //水平方向
float v = Input.GetAxis("Vertical"); //垂直方向
transform.Translate(new Vector3(h, v, 0)*Time.deltaTime*speed);
}
}