Unity-C#

 2024.07.07 unityC#  
 2024.05.15 unityC#  
 2024.05.15 unityC#  
 2022.11.06 unityC#  
 2022.11.06 unityC#  
 2022.11.06 unityC#  
 2022.11.06 unityC#  
 2022.11.06 unityC#  
 2022.08.16 spritekit  

page.phpテンプレートを利用しています。

Bullet


public class Bullet : MonoBehaviour
{
    Rigidbody2D  rbody; 
     public float speed;   
    void Start()
    {
      rbody = this.GetComponent();
     //  playerRb = GameObject.Find("Player").GetComponent();
    }
     void FixedUpdate()
    {
        rbody.velocity = new Vector2(speed, 0);    
    }
    void Update()
    {
    //   rbody.velocity = new Vector2(speed, 0);
     //  transform.position += new Vector3(-15f * Time.deltaTime, 0, 0);
     //  transform.Rotate(0f, 180f, 0f);
     //    transform.position += new Vector3(15f * Time.deltaTime, 0,  0);
     if(transform.position.x > 20.0f )
        {    
             Destroy(gameObject);
         }
      }
    }

Player


public class Player : MonoBehaviour
{
    Rigidbody2D rbody;              //Rigidbody2D型の変数
    float axisH = 0.0f;             //入力
    public float speed = 3.0f;
    public FixedJoystick joystick;  //InspectorからJoystickを取得 
    // Start is called before the first frame update
    void Start()
    {
        //Rigidbody2Dを取ってくる
        rbody = this.GetComponent();
    }

    // Update is called once per frame
     void Update()
    {
      //  axisH = Input.GetAxisRaw("Horizontal");
        axisH = joystick.Horizontal;
        //向きの調整
        if (axisH > 0.0f)
        {
            //右移動
            Debug.Log("右移動");
            transform.localScale = new Vector2(1, 1);
        }
        else if (axisH < 0.0f)
        {
            Debug.Log("左移動");
            transform.localScale = new Vector2(-1, 1);
        }
    }
    void FixedUpdate()
    {
        //速度を更新する
        rbody.velocity = new Vector2(axisH * speed, rbody.velocity.y);
    }
}