0
点赞
收藏
分享

微信扫一扫

子弹打城墙

白衣蓝剑冰魄 2022-04-14 阅读 50
unity

watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAWF8xMU1pYW9NaWFv,size_20,color_FFFFFF,t_70,g_se,x_16

 watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAWF8xMU1pYW9NaWFv,size_20,color_FFFFFF,t_70,g_se,x_16分别创建CameraMove,CreatWall,ZiDan三个脚本;

 

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

 

public class CameraMove : MonoBehaviour

{

    public GameObject other;

    public Rigidbody rb;

    public float speed;

    public float Thrust;

    // Start is called before the first frame update

    void Start()

    {

        rb = other.GetComponent<Rigidbody>();

    }

 

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

        if(Input.GetButtonDown("Fire1"))

        {

            Rigidbody ziDan = GameObject.Instantiate(rb, transform.position, transform.rotation);

            ziDan.AddForce(transform.forward * Thrust);

        }

       

 

    }

}

 

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

 

public class CreatWall : MonoBehaviour

{

    public GameObject cube;

    public int x = 9;

    public int y = 5;

    // Start is called before the first frame update

    void Start()

    {

        CreatBrick();

    }

 

    // Update is called once per frame

    void Update()

    {

        

    }

    void CreatBrick()

    {

        for (int i = 0; i < x; i++)

        {

            for (int j = 0; j < y; j++)

            {

                GameObject.Instantiate(cube, new Vector3(i - 4, j, 0), Quaternion.identity);

            }

        }

    }

}

 

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

 

public class ZiDan : MonoBehaviour

{

    public GameObject baoZha;

    private void OnCollisionEnter(Collision collision)

    {

        GameObject baoZhaZhong = GameObject.Instantiate(baoZha, transform.position, transform.rotation);

        //播放声音

        gameObject.GetComponent<AudioSource>().Play();

        gameObject.GetComponent<MeshRenderer>().enabled = false;

        gameObject.GetComponent<SphereCollider>().enabled = false;

        GameObject.Destroy(baoZhaZhong, 3.0f);

        GameObject.Destroy(this.gameObject);

    }

}

举报

相关推荐

0 条评论