脚本一
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class one : MonoBehaviour
{
// Start is called before the first frame update
public OneScriptsTowObject First;
void Start()
{
}
// Update is called once per frame
void Update()
{
if(Input.GetKeyDown(KeyCode.K))
{
First.num++;
Debug.Log("One : " + First.num.ToString());
}
}
}
脚本二
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Tow : MonoBehaviour
{
// Start is called before the first frame update
public OneScriptsTowObject Sceond;
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.S))
{
Sceond.num++;
Debug.Log("Second : " + Sceond.num.ToString());
}
}
}
通用脚本
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class OneScriptsTowObject : MonoBehaviour
{
// Start is called before the first frame update
public int num;
void Start()
{
num = 0;
}
// Update is called once per frame
void Update()
{
}
}