unity3d - Why is my Object not filled -
i trying create select object script in unity.
what should when hover on object colors red (and does) , when press "1" gameobject's targethighlighted
filled object hovering on @ moment. in debug.log
works fine, targethighlighted
is filled.
when press "1" targethighlighted
object still left empty. doesn't matter if press while hovering on object or away it.
my full code more extensive this. section of code contains problem, reduced this.
can explain me how come when press "1" the debug.log
doesn't show targethighlighted
or targetselected
?
basically why mouseenter
, mouseexit
log right object, settarget
function doesn't?
using unityengine; using system.collections; public class targetselectionscript: monobehaviour { // store current selected gameobject gameobject targethighlighted; renderer rend; color initialcolor = color.white; color selectedcolor = color.red; public gamecontrollerscript gamecontroller; void start() { } void update() { if (input.getkeydown("1")) { settarget(); } } void onmouseenter() { selecttarget(); } void onmouseexit() { cleartarget(); } void selecttarget() { raycasthit hitinfo = new raycasthit(); physics.raycast(camera.main.screenpointtoray(input.mouseposition), out hitinfo); targethighlighted = hitinfo.transform.gameobject; rend = targethighlighted.getcomponent < renderer > (); rend.material.color = selectedcolor; debug.log("highlighted target: " + targethighlighted); } void cleartarget() { debug.log(targethighlighted); } void settarget() { debug.log(targethighlighted); } }
because no key registered under "1"
for reason, must resort using appropriate keycode
,
if (getkeydown(keycode.alpha1)) settarget();
Comments
Post a Comment