Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 08 Dec 2006
Offline Last Active Oct 06 2014 12:00 PM

#5172289 Battleship in java

Posted by on 08 August 2014 - 08:58 AM

I don't want to argue semantics with people, I just want to know how to optimize my code. 


He was not arguing semantics, he was informing you that you didn't really do what was suggested to you.


Doing what has been suggested, breaking down specific tasks into separate methods, you should be able to end up with a main method that looks similar to rip-offs main.  This will help with readability and maintainability and will give you specific, contained areas of code to work with to optimize.  

#5145330 using a graphical icon as a button

Posted by on 08 April 2014 - 07:46 AM



OnMouseOver works but is called every frame that the mouse is over the object.  There is also OnMouseEnter and OnMouseExit to simulate Hover events (each only called one time when the action is observed).  You could do something like this in C#.

using UnityEnging;
using System.Collections;

public class ButtonController : MonoBehaviour{

	// set via the inspector
	public Texture2D hoverTexture = null;
	// cached components
	private GUITexture myGUITexture = null;
	private Texture2D defaultTexture = null;
	// SceneManager is a singleton - see Scripting Reference for
	// FindObjectOfType for a hint on how to implement
	private SceneManager scene = null;	
	void Start(){
		scene = SceneManager.Instance;
		myGUITexture = GetComponent<GUITexture>();
		defaultTexture = (Texture2D) myGUITexture.texture;
	void OnMouseEnter(){
		myGUITexture.texture = hoverTexture;
	void OnMouseExit(){
		myGUITexture.texture = defaultTexture;
	void OnMouseUpAsButton(){
		// SceneManager defines a funciton that takes a string and depending on 
		// which button is pressed it takes a different action.
		// this way all of your button logifc is in one component and you can have
		// a single button script instead of each button needing it's own script logic.

Also, you should note that you are not limited to using GuiTextures/GuiText as buttons.  This is considered the "Legacy" GUI system by Unity.  Check the references for GUI.  I must admit that I do happen to like the legacy system more for things just like simple image buttons and labels, but if you need more complex controls (sliders, dialogboxes, input controls, etc) then you should use the GUI class.  Check the scripting reference.


Believe it or not, you don't need to use either of those if you don't want to.  Any object in the game that has a collider can override the functions in the script above so you can use 3DText, a character, etc as a button.   Instead of changing the texture you could offset it towards the camera to make it bigger, you could have it enter an animation sequence, you could have it change pose, etc.  The script is almost the same other than that.


Hope this helps.

#5143763 spawn GameObject at certain position

Posted by on 01 April 2014 - 02:00 PM

sorted it, my start() contained a vector3 which was positioning it at 000. i removed that and created a call to the spawnmethod on creating the scene sending it a vector3 instead

Glad you figured it out.  I didn't see anything in the code above that would have caused your issue.  It is quite often that the offending code is often left out of posts where unexpected results are occurring.


Nonetheless, it is always a good idea to return to your posts with the solution, even if found by yourself.  I commend you for that.

#4805917 Osama Bin Laden is Dead.

Posted by on 03 May 2011 - 06:41 AM

Posted Image

Pictures like this do a great job of strengthening national stereotypes. Street-parties, waving flags and chanting "USA. USA. USA" because someone was assassinated. It's more weird than anything else.

Big difference between these celebrations and world wide celebrations when the WTC went down. While I do not think it was *right* or *smart* for these KIDS (who were probably about 10 years old when 9/11 happened) to be dancing and celebrating in the streets - they are celebrating the death of a mastermind terrorists. They are not burning flags, they are not celebrating the death of thousands of innocents. The specific event that they are celebrating is deserving of some acknowledgement.

My specific reaction was, "About time we got him. Wish it had been quicker and cheaper (in terms of $$$ and lives). Well, in reality, I don't think it really *changes* anything. The same people that wanted to hurt us before - still want to hurt us. I don't think there are really many more because of his death that want to hurt us."

I think the acting of this kids is more likely to bring bad sentiments towards the US than the actions that the US took the other day.

Regardless, if we have been isolationists for the last 200 years - the same people that hate us for meddling in foreign affairs would hate us for ignoring their calls for help.

#4791736 Google Interview Questions

Posted by on 29 March 2011 - 08:51 AM

What about x=0? That has the same as above, but adds in that there is some number representing no quantity at all.

Nope. that equals 2, not 0.