打砖块

创建plane与小球方块的prefab
打砖块_第1张图片
打砖块_第2张图片
打砖块_第3张图片
创建一堵墙

public class Bricks : MonoBehaviour {
	public GameObject bricks;
	private int columnNum = 8;
	private int rowNum = 6;

	// Use this for initialization
	void Start () {
		for (int i = 0;i

打砖块_第4张图片
小球代码(使小球射出后消失):

public class BallDestory : MonoBehaviour {

	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
		Destroy(this.gameObject,3f);
	}
}

摄像机代码(能控制视角移动并发射小球)

public class Shoot : 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);
		}
	}
}

打砖块_第5张图片

你可能感兴趣的:(打砖块)