x


Get object name from raycast.

Hey. I'm trying to get a gameobject's name using raycast, and set it to a var. But exexuting the code give me the error "(11,41): BCE0034: Expressions in statements must only be executed for their side-effects."

Heres my code.

public var myNewTexture2D:Texture2D;

function Update ()
{
   if ( Input.GetMouseButtonDown(1) )
   {
      var hit : RaycastHit;
      var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition);
      if (Physics.Raycast (ray, hit, 100.0))
      {
        hit.collider.gameObject.name;
         //RaycastHit.collider;
         renderer.material.mainTexture = myNewTexture2D; 
         renderer.material.SetColor ("_SpecColor", Color.red);
         Debug.Log(hit.collider.gameObject.name);
      }
   }
}
more ▼

asked Oct 09 '10 at 01:14 PM

Tommy gravatar image

Tommy
156 20 22 27

You don't need the "gameObject". "name" is a property of Object.

Oct 09 '10 at 04:06 PM Jessy
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

hit.collider.gameObject.name;

Just putting a variable on a line by itself generates that error.

You need to assign something to it or assign it to something. :)

more ▼

answered Oct 09 '10 at 03:42 PM

Loius gravatar image

Loius
10.5k 1 11 41

Or, just get rid of that line - you are already printing it out a few lines later. Looks like it was just a cut-and-paste error.

Oct 09 '10 at 03:48 PM Bampf
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2074
x1525
x1089
x143
x7

asked: Oct 09 '10 at 01:14 PM

Seen: 7414 times

Last Updated: Oct 09 '10 at 01:14 PM