Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Sebulec · Dec 08, 2013 at 04:48 PM · c#tower-defense

Problem with TD script (from java to c#)

Hi guys. I'm making Tower Defence game and i stuck in scrip which i translated from java to c#. I have 3 errors and i can't solve them

  1. Assets/Skrypty/InGAmeGUI.cs(64,53): error CS0266: Cannot implicitly convert type UnityEngine.Object' to UnityEngine.GameObject'. An explicit conversion exists (are you missing a cast?)

  2. Assets/Skrypty/InGAmeGUI.cs(66,64): error CS1612: Cannot modify a value type return value of UnityEngine.Transform.localEulerAngles'. Consider storing the value in a temporary variable 3. Assets/Skrypty/InGAmeGUI.cs(95,25): error CS0103: The name buildPanelTweener' does not exist in the current context

    using UnityEngine; using System.Collections;

    public class InGAmeGUI : MonoBehaviour {

      //NGU items
         
         public bool buildPanelOpen = false;
         public TweenPosition BuildPanelTweener; 
         public TweenRotation BuildPanelArrowTweener;
         
         //Placement Plane Items
         public Transform placementPlanesRoot; // attach the placement plane root
         public Material hoverMat; // attach the hover material to this slot
         public LayerMask placementLayerMask; // calls up the layer mask selection
         private Material originalMat;
         private GameObject lastHitObj;
         
         //Build Selection Items
         public Color onColor;
         public Color offColor;
         public GameObject[] allStructures;
         public UISlicedSprite[] buildBtnGraphics;
         
         private int structureIndex = 0;
         
         void Start ()
         {
             //reset the structure index, refresh the GUI
             structureIndex = 0;
             UpdateGUI();
         }
         
         void Update ()
         {
             if ( buildPanelOpen )
             {
                  var ray = Camera.main.ScreenPointToRay ( Input.mousePosition );
                 RaycastHit hit;
                 if ( Physics.Raycast ( ray,out hit, 1000, placementLayerMask ) )
                 {
                     if ( lastHitObj )
                     {
                         lastHitObj.renderer.material = originalMat;
                     }
                     lastHitObj = hit.collider.gameObject;
                     originalMat = lastHitObj.renderer.material;
                     lastHitObj.renderer.material = hoverMat; // sets the planes material to the highlighted material
                 }
                 else // if the raycast didn’t hit anything
                 {
                     if ( lastHitObj ) // if we had previously hit something
                     {
                         lastHitObj.renderer.material = originalMat; // visually de select that object
                         lastHitObj = null; // nullify the plane selection
                     }
                 }
                 // drops a turrent on click
                 if ( Input.GetMouseButtonDown(0) && lastHitObj ) //left mouse button was clicked and there is a last hitObject // if left mouse button (0) is clicked and we have something selected
                 {
                     if(lastHitObj.tag =="PlacementPlane_Open")
                     {
                         // drop the chosen structure exactly at the tile’s position and rotation of Zero. See how the “index” comes into play here?
                         GameObject  newStructure = Instantiate( allStructures[structureIndex], lastHitObj.transform.position, Quaternion.identity );
                         // set the new structure to have a random rotation. just for looks
                         newStructure.transform.localEulerAngles.y = (Random.Range(0, 360));        //newStructure.transform.localEulerAngles.y = ( Random.Range ( 0, 360 ) );
                         // set this tile’s tag to “Taken” so we can’t double place a structure
                         lastHitObj.tag = "PlacementPlane_Taken";        
                     }
                 }
             }
         }
         
         void UpdateGUI () {
         
             //Go through all structure buttons (buttons in the build panel). and set them to “off”
             foreach(UISlicedSprite theBtnGraphic in buildBtnGraphics )//in buildBtnGraphics
             {
                 theBtnGraphic.color = offColor;
             }
             //set the selected build button to “on”
             buildBtnGraphics[structureIndex].color = onColor;
         }
         
         // this happens whenever the build arrow is clicked
         void ToggleBuildPanel ()
         {
             if ( buildPanelOpen ) {
                 // hide all build tiles
                 foreach(Transform thePlane in placementPlanesRoot) 
                 {
                     thePlane.gameObject.renderer.enabled =false;
                 }
                 // plays the build panel tweener script backward ( false )
                 buildPanelTweener.Play ( false );
                 // sets the boolean to false ( closed )
                 buildPanelOpen = false; 
             }
             
     
             else // the build panel was closed, so instead do this…
             {
                 BuildPanelTweener.Play(true);
                 BuildPanelArrowTweener.Play(true);
                 foreach ( Transform thePlane in placementPlanesRoot )
                 {
                     thePlane.gameObject.renderer.enabled = true;
                 }
     
             }
         }
         // Called whenever a structure choice is clicked ( the button in the build panel )
         void SetBuildChoice ( GameObject btnObj )
         {
             string btnName = btnObj.name;
             if ( btnName == "Btn_Farmer")
             {
                 structureIndex = 0;
             }
             else if ( btnName == "Btn_Cow" )
             {
                 structureIndex = 1;
             }
             else if ( btnName == "Btn_Alien")
             {
                 structureIndex = 2;
             }
             UpdateGUI ();
         }
     } 
    
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image tomekkie2 · Dec 08, 2013 at 04:59 PM 1
Share

Line 64 - Instantiate outputs an Object, so you should cast adding

 as GameObject

... But you should "re-format" the script in your question, because the line numeration got wrong.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Fornoreason1000 · Dec 08, 2013 at 04:58 PM

Here you create a Object (not object) and assign it to a GameObject, you can use a cast like @tomekkie2 said, or use GameObject.Instantiate. Line64:

 GameObject  newStructure = GameObject.Instantiate( allStructures[structureIndex], lastHitObj.transform.position, Quaternion.identity );


This is more of a C# design error, you can't assign one part of a vector, you need to change the whole thing(its weird I know). you can do this by creating a new vector with the same values except the ones you changed then assign it. Line66:

   newStructure.transform.localEulerAngles = new Vector3(
   newStructure.transform.localEulerAngles.x, 
   (Random.Range(0, 360)),
   newStructure.transform.localEulerAngles.z);


As for Line 95, you need to set the execution order for build panel tweener. based on that error, is probably still in Unityscript("Javascript"). are you planning to convert that to C#?

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Sebulec · Dec 08, 2013 at 08:30 PM 0
Share

No i am using NGUI i forgot to write it. I'm learning from (i don't know if i can add link if not delete it) http://cgcookie.com/unity/lessons/3b-turret-placement/

avatar image Sebulec · Dec 08, 2013 at 08:47 PM 0
Share
     if(lastHitObj.tag =="PlacementPlane_Open")
                     {
                         // drop the chosen structure exactly at the tile’s position and rotation of Zero. See how the “index” comes into play here?
                         var newStructure = GameObject.Instantiate( allStructures[structureIndex], lastHitObj.transform.position, Quaternion.identity );
                         
                         // set the new structure to have a random rotation. just for looks
                         var newStructure.transform.localEulerAngles.y = (Random.Range(0, 360));        //newStructure.transform.localEulerAngles.y = ( Random.Range ( 0, 360 ) );
                         // set this tile’s tag to “Taken” so we can’t double place a structure
                         lastHitObj.tag = "PlacementPlane_Taken";        
                     }

i made it like this and now i have error :Assets/Skrypty/InGAmeGUI.cs(68,57): error CS1525: Unexpected symbol .', expecting )', ,', ;', [', or ='

avatar image Fornoreason1000 · Dec 08, 2013 at 10:03 PM 0
Share

I get no errors with that code.... only that you still haven't changed line 68(which isn't the error)

avatar image Sebulec · Dec 09, 2013 at 07:13 PM 0
Share

I can't make it correct. What i should do ? I tried everything but i still get error Assets/Skrypty/InGAmeGUI.cs(68,57): error CS1525: Unexpected symbol .', expecting)', ,',;', [', or=' 68. var newStructure.transform.localEulerAngles.y = (Random.Range(0, 360)); //newStructure.transform.localEulerAngles.y = ( Random.Range ( 0, 360 ) );

avatar image Fornoreason1000 · Dec 09, 2013 at 10:04 PM 0
Share
  if(lastHitObj.tag =="PlacementPlane_Open")
           {
               // drop the chosen structure exactly at the tile’s position and rotation of Zero. See how the “index” comes into play here?
               GameObject newStructure = GameObject.Instantiate( new GameObject(), lastHitObj.transform.position, Quaternion.identity ) as GameObject;
  
               // set the new structure to have a random rotation. just for looks
                newStructure.transform.localEulerAngles = new Vector3(0, (Random.Range(0, 360)));       //newStructure.transform.localEulerAngles.y = ( Random.Range ( 0, 360 ) );
               // set this tile’s tag to “Taken” so we can’t double place a structure
               lastHitObj.tag = "PlacementPlane_Taken";     
           }

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Distribute terrain in zones 3 Answers

Multiple Cars not working 1 Answer

Saving final score and displaying on main menu 1 Answer

null texture passed to GUI.DrawTexture 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges