Комментарии:
So lets say I'm trying to get a separate script component from the parent object of my script, as you are in your first example.
What happens if there are multiple components of the target type belonging to the parent? Is only the first one returned? Is a list returned? What is the behavior?
This is very good, thank you for the help.
Ответить<3
Ответитьajudou!!!!! estava horas pesquisando sobre um erro que estava dando neste GetComponent
ОтветитьHello, I had a question. In C#, we were doing the instance import by saying new. Here, we do it by saying GetCompanent. Are these two processes actually the same thing? Confusingly, when the new update was made, the entered values were stuck somewhere in the stack. In GetCompanent, we can see the values of an object we received from the inspector. So in a way, we're reaching. The two seem a little different to me. I would be glad if you enlighten me.
ОтветитьGood scripting
ОтветитьI hate this tutorial so much.
ОтветитьHi everyone, just a question to fully understand this (very good) tutorial (imo): The anotherScript and yetAnotherScript variables here hold instances of the two custom classes AnotherScript and YetAnotherScript which can then be accessed in this class (which is UsingOtherComponents) ; is that correct?
ОтветитьThe naming conventions were unnecessarily obtuse and I walked away with more questions than answers. I'd recommend making the video longer with several examples, starting each from scratch.
Ответитьive been trying to do somthing and i just cant figure it out
im willing to try pretty much anything at this point
using UnityEngine;
public class Orange_Block : MonoBehaviour
{
public bool moves;
public move Move;
void Describe()
{
Move = GetComponent<move>();
}
void OnTriggerEnter()
{
Move = GetComponent<move>();
if (Input.GetKey("a") || Input.GetKey("d"))
{
moves = true;
}
else
{
moves = false;
}
if (moves == false)
{
Move.enabled = false;
FindObjectOfType<GameOver>().endgame();
}
}
}
"move" is the component im trying to acces from another object and "Move" is what i named it
any clues in what im doing wrong?
Can we use Getcomponent to get Bools?
ОтветитьTHANK U, BETTER ORIGINAL THAN THE OTHER ONES
ОтветитьTHANK YOU SO MUCH!!!
ОтветитьTanks this is really help full
Ответитьwhere is the video that was 'linked below on classes'? :) any hookups?
ОтветитьThe player's score is over 9000, that's cheeky lol
Ответитьlol. They left out the hard and useful part. You see, it's easy to use GetComponent when you can first use a 'public otherGameObject' and then drag and drop some GameObject into there. Then you just reference that with GetComponent. Easy! And then.... you start using preFabs and you can't do this. But you still need that original otherGameObject reference. So you have to code it in using GameObject.find - hope that saves you all the trouble I went through. Remember... step one is referencing the other GameObject. And if you can't drag and drop you have to use GameObject.find.... and there are several options. Find by name. Find by tag, etc. Also... when you do this, you learn that gameObjects are created in a sequence so if you try to refer to one that hasn't been created yet it will return null. Good luck everyone.
ОтветитьSo if GetComponent is expensive, but I still need constant access to another script's variables and methods, what option do I have?
Ответить10 seconds of this video helped me more than 1 hour trying to figure this out by myself. Thanks!
Ответитьconfusing
ОтветитьReally what you need to know, GetComponent by itself is a "LOCAL" function (or rather local to a single game object) that grabs components on game objects that the script is attached to. If you want to grab components on OTHER game objects, you have to REFERENCE those game objects into the script first, THEN you can use the local GetComponent once the other object is referenced in.
public GameObject otherGameObject; <------ this is the reference to ANOTHER object in the game. NOW we can use GetComponent on that object like usual. Without this, you can only access components on the game object that the script is attached to.
private variable = otherGameObject.GetComponent<desired component here>(); <----- this is creating a new variable in the current script and giving us access to the other game object's components.
If anyone watching this is still confused like I was, look up Charger Games - GetComponent Function in Unity C#
ОтветитьI have a question, what if I what to get some values of an object, like the diameter of a spere, what should I do?
ОтветитьDanndx's "Unity C# - How to interact between scripts" will help you much better
Ответитьas said in the video, using 'getcomponent' is expensive in terms of processing power. So in place of that can we use a public variable of type 'anotherscript' and then attach that script in the unity editor??
ОтветитьА как редактировать то блять
ОтветитьI can't seem to reference my script, I have been following it through but I am still having an issue. The scripts are on the same gameobject so I am not sure what is the issue
ОтветитьNOTHING WORKS!!!!!!!!!!!!!!!!!!!!!!! I have the scripts in the same object and one is named slide and one is named first person controller. From first person controller i and doing private slide slide; and it says thats incorrect
Ответитьthank you.
I have a unity issue now.
can you help me?
Thanks. I’ll try this out. I’m familiar with other programming languages, but I found unity’s scripting for accessing other objects and the object’s components difficult.
I think this new info will help me out.
this is explained awfully
ОтветитьHello, I get the error "The type or namespace name 'AnotherScript' could not be found (are you missing a using directive or an assembly reference?)"
I have of course replaced AnotherScript with my actual script name.
Thank you. This tutorial really helped me I couldn't find a solution for a few hours and this is the first thing that worked.
Ответитьi think the current design of unity is cool its good for rapid prototyping. ecs is currently confusing alot more code. i know dots/ecs isn't a replacement for the current monobehavior unity will forever have it. dots/ecs is like angular while you only needed basic html which is monobehavior.
Ответитьthank you, these videos are very helpful
ОтветитьThanks Unity and Microsoft.But Please Upgrade design system and design interface in Unity.
Ответитьhard
Ответить