前提
現在unityにてシューティングゲームを作っています。
以下のC#スクリプトを弾のオブジェクトにアタッチメントしています。
今のままでは、右に直進するだけですが、これを弾のオブジェクトのLocalRotationのZの向きに進むようにしたいと考えています。
一体どのようなコードにすべきか教えていただきたいです。
該当のソースコード
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class bullet : MonoBehaviour
{
//インスペクターで設定する
[Header("弾速度")] public float bullet_speed;//弾速度
[Header("弾")] public GameObject Bullet;
//プライベート変数 private Rigidbody2D rb = null; void Start() { rb = GetComponent<Rigidbody2D>(); } // Update is called once per frame void Update() { rb.velocity = new Vector2(bullet_speed, 0); }
}
あなたの回答
tips
プレビュー