《打砖块》教程知识梳理

Posted on 2019-07-15 16:53  小木book  阅读(145)  评论(0)    收藏  举报
 1 using System.Collections;
 2 using System.Collections.Generic;
 3 using UnityEngine;
 4 
 5 public class shoot : MonoBehaviour {
 6 
 7 public GameObject bullet;
 8 public float speed = 5;
 9 private float time = 0;
10 private float timer = 3;
11 public GameObject b;
12 // Use this for initialization
13 void Start () {
14 Debug.Log("--Hellow Unity!");
15 // GameObject.Instantiate(bullet,transform.position,transform.rotation);
16 }
17 
18 // Update is called once per frame
19 void Update () {
20 
21 if(Input.GetMouseButtonDown(0))
22 {
23 
24 b = GameObject.Instantiate(bullet, transform.position, transform.rotation);
25 Rigidbody rgd = b.GetComponent<Rigidbody>();
26 rgd.velocity = transform.forward * speed;
27 
28 
29 }
30 
31 }
32 }
View Code