Hello
Guest
Home
Help
Search
Login
Register
2D Toolkit Forum
»
2D Toolkit
»
Support
»
How do I reference 2dtk objects in code?
« previous
next »
Print
Pages: [
1
]
Author
Topic: How do I reference 2dtk objects in code? (Read 5526 times)
jakecattrall
Newbie
Posts: 6
How do I reference 2dtk objects in code?
«
on:
May 24, 2013, 01:47:16 pm »
I got this far:
Code:
[Select]
GameObject _tileMap = GameObject.Find("TileMap");
Presumably that gets my tilemap object, but then what?
On a general note, it would be nice to see some detailed code examples in the script reference.
«
Last Edit: May 24, 2013, 02:23:17 pm by jakecattrall
»
Logged
unikronsoftware
Administrator
Hero Member
Posts: 9709
Re: How do I reference 2dtk objects in code?
«
Reply #1 on:
May 24, 2013, 04:27:43 pm »
You shouldn't do that really - GameObject.Find is pretty slow, especially so if you do it every frame.
Check the Unity tutorials on how to reference objects, etc. The best way is to create a public variable in your object, and then simply drag and drop a reference in the Unity interface. No finding, and a reliable link to the object permanently.
Expanded the code samples in the tk2d 2.0 tutorial a bit more:
http://unikronsoftware.com/2dtoolkit/docs/2.00/
Logged
Artheus
Newbie
Posts: 19
Re: How do I reference 2dtk objects in code?
«
Reply #2 on:
November 04, 2013, 09:51:51 pm »
Sorry to bring up an old topic but I'm writing an editor script and can't use the drag and drop to make a reference to the tilemap. In this case, is GameObject.Find() my best option?
Logged
unikronsoftware
Administrator
Hero Member
Posts: 9709
Re: How do I reference 2dtk objects in code?
«
Reply #3 on:
November 05, 2013, 12:08:18 pm »
GameObject.Find is fine from editor scripts, its just very slow at runtime.
Logged
Print
Pages: [
1
]
« previous
next »
2D Toolkit Forum
»
2D Toolkit
»
Support
»
How do I reference 2dtk objects in code?