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 voba@tud · Nov 22, 2012 at 10:27 AM · unity 4constructor

Constructor Problem in Unityscript

I made a class target:

 class Target{
     public var target : Transform;
     
     public var rotationTarget : Transform;
     public var rotationVector : Vector3;
     
     
     public var centerAktion : Aktionen;
     public var centerTransform : Transform;
     
     public var action : Aktionen;
     public var actionTime : float;
     public var actualGO : GameObject;
     
     
 //0
     public function Target(actualGO: GameObject){
         //zu 1
         Target(actualGO, Aktionen.Stand, new Vector3(0,1,0));
         Debug.Log("after Init 1:"+this.toString());
 
     }    
 //1    
     public function Target(actualGO : GameObject, action : Aktionen, target : Vector3){
         var temp : Transform = new GameObject().transform;
         try{
             TransformRotationArray.Instance.Add(temp, actualGO.name+"_"+action);
             temp.position = target;
         }catch(e : Exception){
             Debug.Log("Problem in TransRotTarget");
         }
         //zu 4
         Target(actualGO, action, temp);
         Debug.Log("after Init 4:"+this.toString());
 
     }
 //2
     public function Target(actualGO : GameObject, action : Aktionen, target : Vector3, rotationVector : Vector3){
         var temp : Transform = new GameObject().transform;
         temp.position = target;
     //    Debug.Log(gameObject);
         TransformRotationArray.Instance.Add(temp, actualGO.name+"_"+action);
         //zu 8
         Target(actualGO, action, temp, rotationVector);
     }
 //3
     public function Target(actualGO : GameObject, action : Aktionen, target : Vector3, rotationTarget : Transform){
         var temp : Transform = new GameObject().transform;
         temp.position = target;
         TransformRotationArray.Instance.Add(temp, actualGO.name+"_"+action);
         //zu 4
         Target(actualGO, action, temp, rotationTarget);
         Debug.Log(this);
 
     }
 //4
     public function Target(actualGO : GameObject, action : Aktionen, target : Transform){
         //zu 6
         Target(actualGO, action, target, target);
         Debug.Log("after Init 6:"+this.toString());
 
     }
 //5
     public function Target(actualGO : GameObject, action : Aktionen, centerAktion : Aktionen, target : Transform){
         //zu 6
         Target(actualGO, action, centerAktion, target, target);
     }
 //6
     public function Target(actualGO : GameObject, action : Aktionen, target : Transform, rotationTarget : Transform){
         //zu 7
         Target(actualGO, action, action, target, rotationTarget);
         Debug.Log("after Init 7:"+this.toString());
 
     }
 //7
     public function Target(actualGO : GameObject, action : Aktionen, centerAktion : Aktionen, target : Transform, rotationTarget : Transform){
         
         this.actualGO = actualGO;
         this.rotationTarget = rotationTarget;
         this.target = target;
         this.action = action;
         rotationVector = Vector3.zero;
 //        Debug.Log("Fehler: "+actualGO + " a:" + action + " ca:"+centerAktion+ " t:"+target+ " rt:"+rotationTarget);
         centerTransform = actualGO.Find(centerAktion+"").transform;
         
         if(action != Aktionen.Stand && centerAktion != Aktionen.Stand)
             actionTime = GameObject.FindWithTag("Ball").GetComponent(BallScript).getTForVector(target.position);
         Debug.Log("in Init 7:"+this.toString());
 
 //        Debug.Log(actualGO.name + " ziel: "+ target.name + " " + action +" "+centerTransform);
     }
 //8
     public function  Target(actualGO : GameObject, action : Aktionen, target : Transform, rotation : Vector3){
         //zu 9
         Target(actualGO, action, action, target, rotation);
     }
 //9
     public function Target(actualGO : GameObject, action : Aktionen, centerAktion : Aktionen, target : Transform, rotation : Vector3){
     //    Debug.Log(gameObject.name + " ziel: "+ target + " " + action +" "+centerAktion);
 
         this.actualGO = actualGO;
         this.action = action;
         this.target = target;
         this.rotationVector = rotation;
         centerTransform = actualGO.Find(centerAktion+"").transform;
         if(action != Aktionen.Stand && centerAktion != Aktionen.Stand)
             actionTime = GameObject.FindWithTag("Ball").GetComponent(BallScript).getTForVector(target.position);
         timeUntilHighestPoint = Helper.getTForYMax(Helper.getVY0(centerTransform.position.y, target.position.y));
         
     //    Debug.Log(gameObject.name + " ziel: "+ target + " " + action +" "+centerPosition);
     
     }
     
 public function toString():String{
         return "Target String: "+actualGO + " a:" + action + " ca:"+centerAktion+ " t:"+target+ " rt:"+rotationTarget + " ct:"+centerTransform+" at:" + actionTime;
 
     
     }
 }

Should work fine, Problem is, when Constructor 7 is called and comes back to Constructor 6, it forgets the whole Object, here is the output:

 in Init 7:Target String: Gegner 5 (UnityEngine.GameObject) a:Stand ca:0 t:TempTarget_11_Gegner 5_Stand (UnityEngine.Transform) rt:TempTarget_11_Gegner 5_Stand (UnityEngine.Transform) ct:Stand (UnityEngine.Transform) at:0
 UnityEngine.Debug:Log(Object)
 Target:.ctor(GameObject, Aktionen, Aktionen, Transform, Transform) (at Assets/Prefabs/Männchen/Target.js:88)
 Target:.ctor(GameObject, Aktionen, Transform, Transform) (at Assets/Prefabs/Männchen/Target.js:71)
 Target:.ctor(GameObject, Aktionen, Transform) (at Assets/Prefabs/Männchen/Target.js:59)
 Target:.ctor(GameObject, Aktionen, Vector3) (at Assets/Prefabs/Männchen/Target.js:33)
 Target:.ctor(GameObject) (at Assets/Prefabs/Männchen/Target.js:19)
 komController:Start() (at Assets/Prefabs/Männchen/komController.js:53)
 
 after Init 7:Target String:  a:0 ca:0 t: rt: ct: at:0
 UnityEngine.Debug:Log(Object)
 Target:.ctor(GameObject, Aktionen, Transform, Transform) (at Assets/Prefabs/Männchen/Target.js:72)
 Target:.ctor(GameObject, Aktionen, Transform) (at Assets/Prefabs/Männchen/Target.js:59)
 Target:.ctor(GameObject, Aktionen, Vector3) (at Assets/Prefabs/Männchen/Target.js:33)
 Target:.ctor(GameObject) (at Assets/Prefabs/Männchen/Target.js:19)
 komController:Start() (at Assets/Prefabs/Männchen/komController.js:53)

What am i doing wrong?

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
0

Answer by voba@tud · Nov 22, 2012 at 12:04 PM

Did it myself. Don't use the constructor to forward the request.

Use this(....,...,...) for the other constructors.

Have a nice day.

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

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

9 People are following this question.

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

Related Questions

Writing constructor to take coordinates 0 Answers

constructor doesn't work in C# native class 1 Answer

Serialized Parameter Constructor? 1 Answer

shader causes triangles to dissapear in U4 (worked in U3) 0 Answers

Networking with Linux 1 Answer


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