unity find gameobject by name
GameObject enemy = GameObject.Find("enemy");
unity find gameobject by name
GameObject enemy = GameObject.Find("enemy");
unity get component
using UnityEngine;
public class TryGetComponentExample : MonoBehaviour
{
void Start()
{
// Since Unity 2019.2 you can use TryGetComponent to check
// if an object has a component, it will not allocate GC in
// the editor if the object doesn't have one.
if (TryGetComponent(out Rigidbody rigidFound))
{
// Deactivate rigidbody
rigidFound.enabled = false;
}
// For versions below 2019.2 you can do it this way:
// Create a variable
Rigidbody rigidFound = GetComponent<Rigidbody>();
// If the 'Rigidbody' exist in the gameobject
if(rigidFound != null)
{
// Deactivate rigidbody
rigidFound.enabled = false;
}
}
}
unity get object by name
function Update() { var enemy : GameObject = GameObject.Find("enemy"); //perform operations on enemy here}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us