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
0
Question by sdgd · Feb 15, 2013 at 01:50 PM · c#windowboolstructresizing

Structure Booling false when created and not enter C#

I wish I wouldn't have to make a bool from where I'm refering the bool in beginning

as if I make it in middle I can't have it true if mouse down as it'll make it false next frame

OR bool won't be assigned

and in structure it doesn't work too since I must not assign them in beginning as in code the commented one

and I don't want to change it to a Class

is there anykind of solution or I must necessarily instantiate it in beginning for a structure

 using UnityEngine;
 using System.Collections;
 
 public struct ResizeWindow {
 //    public bool Resize = false;
     public void ResizeF (ref bool Resize, ref Rect ResizingWindow){
         if (Event.current.type.ToString() == "mouseDown"){
             Resize = true;
         }
         
         if (Resize){
             ResizingWindow = new Rect (0,0,Event.current.mousePosition.x + 1,Screen.height/3);
             Debug.Log("sdpiorghn");
             if (Event.current.type.ToString() == "mouseUp"){
                 Resize = false;
             }
         }
     }
 }


OR how would I create it false when I instantiate this structure?

 ResizeWindow Resize.Resize = false;

or

 ResizeWindow Resize = new ResizeWindow (Resize = false);

or something like that

so when it's created I automatically

if that's not possible just let me know

OR how would I do something that GUI.Dragwindow has? so I wouldn't need to instantiate stuff or ref or pass values

thanks in advance

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Paulo-Henrique025 · Feb 15, 2013 at 02:16 PM

Try a constructor to set the bool when the structure is instantiated

 using UnityEngine;
 using System.Collections;
 
 public class TestStruct : MonoBehaviour {
     
     public struct MyStruct
     {
         public bool isAlive;
         
         public MyStruct(bool setAlive)
         {
             isAlive = true;
         }
         
     }
     
     // Use this for initialization
     void Start () 
     {
         MyStruct ms = new MyStruct(true);
         Debug.Log(ms.isAlive);
     }
 }

 
Comment
Add comment · Show 2 · 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 sdgd · Feb 15, 2013 at 04:24 PM 0
Share

wow tried the code and did a few tweaks and it worked

I thought structures can't have a constructors

I was trying something like this before but it just didn't work

any way my working code now

 using UnityEngine;
 using System.Collections;
 
 public struct $$anonymous$$yStructure {
     public bool isAlive;
     public $$anonymous$$yStructure(bool setAlive){
         isAlive = true;
     }
 }


and testing - no errors

 $$anonymous$$yStructure asdf = new $$anonymous$$yStructure(true);

tyvm :)

ahhhh now I get it structures can't have only constructors getting nothing

avatar image Paulo-Henrique025 · Feb 15, 2013 at 04:29 PM 0
Share

Structs share all the base concepts with Classes, take a look: http://stackoverflow.com/questions/4791883/c-struct-vs-class

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

10 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

Related Questions

Invoke on Struct or some else time wait 1 Answer

Accessing variables in a structure in a class from another class with cSharp 3 Answers

Change window size without changing game resolution? 2 Answers

Setting a bool is not working with objects that have already spawned.. 1 Answer

Get bool value from one script to another (C#) 2 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