0
0

More than 3 years have passed since last update.

[Unity] 別のオブジェクトのスクリプトを参照する方法

Posted at

他のゲームオブジェクトのスクリプトを参照するコードです。

構文
    weapon = GameObject.Find(ゲームオブジェクト名(文字列));
    weaponScript = weapon.GetComponent<スクリプト名>();

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

public class MoveControl : MonoBehaviour
{

    //武器
    private GameObject weapon;       //ゲームオブジェクト
    private Weapon weaponScript;    //スクリプト 型はスクリプト名

    void Start()
    {             
        weapon = GameObject.Find("Weapon");
        weaponScript = weapon.GetComponent<Weapon>();   //武器
    }

    void Update()
    {

    }

}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0