新建一個平面,放大到四倍,附上材質ide
新建一個方塊,加上Rigidbody和材質this
編寫腳本,生成一面8*6的牆spa
public class qiang : MonoBehaviour {orm
public GameObject brick;blog
private int columnNum = 8;it
private int rowNum = 6;io
// Use this for initializationform
void Start () {class
for(int i = 0; i < rowNum; i++)transform
{
for (int j=0;j<columnNum;j++)
{
Instantiate(brick, new Vector3(j - 5, i), Quaternion.identity);
}
}
}
建立一個附上材質的小球
編寫發射小球的腳本
public class fashe : MonoBehaviour {
public GameObject shootPos;
private float force = 1000;
public Rigidbody shootBall;
private float speed = 0.1f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
Rigidbody ball;
if(Input.GetKeyDown(KeyCode .Space))
{
ball = Instantiate(shootBall, shootPos.transform.position, Quaternion.identity) as Rigidbody;
ball.AddForce(force * ball.transform.forward);
}
if (Input.GetKey(KeyCode.LeftArrow))
{
this.transform.Translate(Vector3.left * speed);
}
else if (Input.GetKey(KeyCode.RightArrow))
{
this.transform.Translate(Vector3.right * speed);
}
else if (Input.GetKey(KeyCode.UpArrow))
{
this.transform.Translate(Vector3.up * speed);
}
else if (Input.GetKey(KeyCode.DownArrow))
{
this.transform.Translate(Vector3.down * speed);
}
}
}
添加使發射的小球消失的腳本
Destroy(this.gameObject, 10f);