Unity3D - Break_Bricks_Project

版权声明:转载请注明出处 https://blog.csdn.net/qq_42292831/article/details/84372618

Scripts:

1> Camera 视角跟随(offset)

2> WSAD (方向键)控制角色移动

3> Click to shoot 单击发射子弹

4> Animation_Loop 动画循环播放

****************************************************************************************************************************************

一:效果实现

二:Scripts

1> Camera 视角跟随(offset)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraFollowTarget : MonoBehaviour {

    public Transform Succubus;
    public Vector3 offset;
	// Use this for initialization
	void Start () {
        offset = transform.position - bird.position;
	}
	
	// Update is called once per frame
	void Update () {
        transform.position = offset + bird.position;
	}
}

2> WSAD (方向键)控制角色移动

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BirdMovement : MonoBehaviour {

    public float speed_wsad = 20;
    public float speed_mouse = 20;

    // Use this for initialization
    void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
        float h = Input.GetAxis("Horizontal");
        float v = Input.GetAxis("Vertical");
        float d = Input.GetAxis("Mouse ScrollWheel");
        d = d * speed_mouse;
        this.transform.Translate(new Vector3(h, v, d) * Time.deltaTime * speed_wsad);    
    }
}

3> Click to shoot 单击发射子弹

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BirdMovement : MonoBehaviour {

    public float speed = 20;
    public GameObject bullet;

    // Use this for initialization
    void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
        if (Input.GetMouseButtonDown(0))
        {
            //GameObject b = GameObject.Instantiate(this.gameObject, transform.position, transform.rotation);    //暴力分裂效果  transform.position

            GameObject b = GameObject.Instantiate(bullet, new Vector3(transform.position.x, transform.position.y + 2,transform.position.z), transform.rotation);
            Rigidbody rgd = b.GetComponent<Rigidbody>();
            rgd.velocity = this.transform.forward * speed;
        }   
    }
}

4> Animation_Loop 动画循环播放

(选中动画 -> Wrap Mode -> Loop)

猜你喜欢

转载自blog.csdn.net/qq_42292831/article/details/84372618