Hi all,
Does anyone know how to select a game object from scene view by script in editor mode?
thx a lot.
Hi all,
Does anyone know how to select a game object from scene view by script in editor mode?
thx a lot.
Selection.activeGameObject=vWay.gameObject;
I dont know if this is what you mean.
Try this script: (JavaScript)
GameObject.Find(“name of object”)
You need to add some code because i dont know what you want to let him do
Hi
You can try to solve this in this way:
GameObject go = GameObject.Find(“Sword”);
//go will be a gameobject from scene named “Sword”
Also this could be useful:
WeaponScript other = (WeaponScript) go.GetComponent(typeof(WeaponScript));
//other will be WeaponScript from your go - gameobject
Please rep me, because I can’t ask any question
Hmm I answered, but i can’t see this so I try again
You can solve this by:
GameObject go = GameObject.Find(“Sword”);
//go will be a gameobject named “Sword” from a scene
Also you could find this useful:
WeaponScript other = (WeaponScript) go.GetComponent(typeof(WeaponScript));
//other will be a WeaponScript component from your go called before
Please rep me , because I can’t ask any questions
Im a bit unsure of your question bud.
Are you asking how to get a Game Object into a script to operate on it programmatically…?
Either add a public cache of type Game Object, like so…
public GameObject go;
this will now be a slot (can be seen in your inspector panel where that script is applied) where you can simply drag the game object you want to work with into the script.
Once your object is in that slot, anything you programmatically do inside that script will affect the game object you specified in the inspector window for aformentioned script.
incidentally, an example of using it might be something like…
`
void Update()
{
go.transform.translate(Vector3.up * Time.deltaTime);
}
`
this would indeed translate the specified game object as a result of the script controlling it.
Hope that helps.
Here also is a link to Unity Reference about
this will further explain about getting gameobjects into your scripts for control…
It uses the GetComponent method of the Component class that Unity Engine provides.
This method has a number of approaches, some more optimized than others and this is one of those methods that are approached differently between the likes of UnityScript and C# for Unity, mainly due to their language constraints (or lack of!)
Anyway, would you like to no more ?
Hope the above helps, let me know if thats what you were getting at or if im super off the mark and we can try get you a solution more befitting.
Merry nearly xmas !
,
------- . : .
| | ‘.:.’
{}} | .-‘|’-.
=========== *
_ _ (( @ @ )) …’
( \ / ))) o (( '.
\ V / (( <=======
(= ) )). ,. '((
\ _(( ___/ ))\
_ / | \ ()
/ /^/ \
/ "
\
( * ) Weird Snowman
`. * .’ gfj/98
********_*
Gruffy
Declare variable for Game object
GameObject _gameObject;
then
_gameObject = GameObject.Find(“gameobjectname”);
Look to this topic (first answer below ask): c# - Unity prefab script "GameObjects" can't be ones on the scene? - Game Development Stack Exchange