Breakout Clone 打砖块 <Shoot 和 Movement 代码>

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);
	
	}
}

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_50777680/article/details/116946141