Skip to content

Instantly share code, notes, and snippets.

@JunShimura
Last active April 23, 2018 23:50
Show Gist options
  • Save JunShimura/89945b453272d928d7d7e2cf1f73ce92 to your computer and use it in GitHub Desktop.
Save JunShimura/89945b453272d928d7d7e2cf1f73ce92 to your computer and use it in GitHub Desktop.
[Unity初心者Tips]確実に!必要なComponentを入れるRequire ComponentとReset() ref: https://qiita.com/JunShimura/items/6576eb63c19c2c9f0c0a
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(TestClassB))]
[RequireComponent(typeof(TestClassC))]
[RequireComponent(typeof(Rigidbody))]
public class TestClassA : MonoBehaviour
{
[SerializeField]
TestClassB testClassB;
[SerializeField]
TestClassC testClassC;
[SerializeField]
Rigidbody rigidBody;
[SerializeField]
GameController gameController;
[SerializeField]
TestEnemy testEnemy;
private void Reset()
{
testClassB = GetComponent<TestClassB>();
testClassC = GetComponent<TestClassC>();
rigidBody = GetComponent<Rigidbody>();
gameController = FindObjectOfType<GameController>();
if (gameController == null) {
Debug.Log("ERROR!Gamecontroller not found");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment