Skip to content

Instantly share code, notes, and snippets.

@hidsh
Last active December 30, 2020 21:26
Show Gist options
  • Save hidsh/4d85ee1001ac2011552d6be77f7c8fd8 to your computer and use it in GitHub Desktop.
Save hidsh/4d85ee1001ac2011552d6be77f7c8fd8 to your computer and use it in GitHub Desktop.
unity-test: UnityのC#でインスタンスを取得しよう https://dkrevel.com/makegame-beginner/program-beginner-instance/
// https://dkrevel.com/makegame-beginner/program-beginner-instance/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
BoxCollider box = null;
Debug.Log(box);
box = GetComponent<BoxCollider>();
Debug.Log(box);
}
// Update is called once per frame
void Update()
{
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
GameObject g = null;
Debug.Log(g);
g = GameObject.Find("Directional Light");
Debug.Log(g);
}
// Update is called once per frame
void Update()
{
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
GameObject g = null;
Debug.Log(g);
g = GameObject.Find("Directional Light");
Light l = null;
l = g.GetComponent<Light>();
Debug.Log(l);
}
// Update is called once per frame
void Update()
{
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
Vector3 v = new Vector3(); // Vector3はclassではあるが、コンポーネントではない
// コンポーネントではないclassをインスタンス化するには new してやる必要あり
Debug.Log(v);
}
// Update is called once per frame
void Update()
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment