他のゲームオブジェクトのスクリプトを参照するコードです。
構文
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()
{
}
}