2d 空物体实例化发射子弹 围绕旋转
来源:互联网 发布:手机怎么制作网络问卷 编辑:程序博客网 时间:2024/05/17 08:47
using UnityEngine;
using System.Collections;
public class Gun : MonoBehaviour
{
public Rigidbody2D rocket;// Prefab of the rocket.
public float speed = 20f;// The speed the rocket will fire at.
private PlayerControl playerCtrl;// Reference to the PlayerControl script.
private Animator anim;// Reference to the Animator component.
void Awake()
{
// Setting up the references.
anim = transform.root.gameObject.GetComponent<Animator>();
playerCtrl = transform.root.GetComponent<PlayerControl>();
}
void Update ()
{
// If the fire button is pressed...
if(Input.GetButtonDown("Fire1"))
{
// ... set the animator Shoot trigger parameter and play the audioclip.
anim.SetTrigger("Shoot");
audio.Play();
// If the player is facing right...
if(playerCtrl.facingRight)
{
// ... instantiate the rocket facing right and set it's velocity to the right.
Rigidbody2D bulletInstance = Instantiate(rocket, transform.position, Quaternion.Euler(new Vector3(0,0,0))) as Rigidbody2D;
bulletInstance.velocity = new Vector2(speed, 0);
}
else
{
// Otherwise instantiate the rocket facing left and set it's velocity to the left.
Rigidbody2D bulletInstance = Instantiate(rocket, transform.position, Quaternion.Euler(new Vector3(0,0,180f))) as Rigidbody2D;
bulletInstance.velocity = new Vector2(-speed, 0);
}
}
}
using System.Collections;
public class Gun : MonoBehaviour
{
public Rigidbody2D rocket;// Prefab of the rocket.
public float speed = 20f;// The speed the rocket will fire at.
private PlayerControl playerCtrl;// Reference to the PlayerControl script.
private Animator anim;// Reference to the Animator component.
void Awake()
{
// Setting up the references.
anim = transform.root.gameObject.GetComponent<Animator>();
playerCtrl = transform.root.GetComponent<PlayerControl>();
}
void Update ()
{
// If the fire button is pressed...
if(Input.GetButtonDown("Fire1"))
{
// ... set the animator Shoot trigger parameter and play the audioclip.
anim.SetTrigger("Shoot");
audio.Play();
// If the player is facing right...
if(playerCtrl.facingRight)
{
// ... instantiate the rocket facing right and set it's velocity to the right.
Rigidbody2D bulletInstance = Instantiate(rocket, transform.position, Quaternion.Euler(new Vector3(0,0,0))) as Rigidbody2D;
bulletInstance.velocity = new Vector2(speed, 0);
}
else
{
// Otherwise instantiate the rocket facing left and set it's velocity to the left.
Rigidbody2D bulletInstance = Instantiate(rocket, transform.position, Quaternion.Euler(new Vector3(0,0,180f))) as Rigidbody2D;
bulletInstance.velocity = new Vector2(-speed, 0);
}
}
}
}
——————————————————————————------
public class routter : MonoBehaviour {
public Transform tu1;
//public Transform tu2;
void Start () {
//tu1 = GameObject.Find("tupian2").transform;
}
void Update () {
transform.RotateAround (tu1.position, tu1.up, 40 * Time.deltaTime);
//tu2.transform.RotateAround (tu1.position, Vector2.up, 30 * Time.deltaTime);
}
0 0
- 2d 空物体实例化发射子弹 围绕旋转
- 摄像机围绕物体旋转观察
- 2.8.2 发射子弹
- MATLAB 2D 矩阵围绕中心旋转
- 【Unity 3D学习】获取鼠标滑动方向(上下左右)-控制摄像机围绕物体旋转
- 鼠标控制摄像机围绕物体旋转拍摄
- unity 鼠标控制摄像机围绕物体旋转
- Unity实现摄像机围绕物体旋转
- 用unity3d做一个物体围绕另外一个物体旋转。
- unity之RotateAround 一个物体围绕另外一个物体旋转
- 让物体围绕自身某一点旋转的方法 Unity
- unity3d 相机围绕某个物体旋转,四元数*位置
- Unity3d实现物体围绕某一点进行旋转
- UE4创建一个围绕角色旋转的物体
- Unity3D开发之控制摄像机围绕物体旋转 平移 缩放
- unity3D 旋转3D物体
- 围绕旋转
- cocos2d-x发射子弹
- Python标准库:内置函数id(object)
- Linux Shell之sed命令
- 动态链表体验
- 傅里叶变换的性质
- CM开发日志 - 搜索引擎(一)
- 2d 空物体实例化发射子弹 围绕旋转
- hduing1501_判断合并_dfs_数组
- Java中的Object的Wait() 和notify()方法使用时应注意的地方和Thread中的sleep()方法
- (回溯算法)商人怎样安全过河
- git fatal: Path XXX is in submodule XXX
- s3c2440音乐播放器madpaly移植
- ubuntu12.04下安装QT
- 黑马程序员——java基础——我对集合的理解
- 的啊上海现山寨天安门 大大神大神大苏打阿萨德