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 applejuices · Dec 05, 2013 at 02:18 PM · vector3insantiate

The most siplest thing will not work..

edit(Bunny83)
Copied and merged from comment:

 var Firefrom : Transform;
 var currentbrick: GameObject;
 var finalbrick : GameObject;
 ;
 
 function Update ()
 {
     if(Input.GetButtonDown("Fire1"))
     {
         var hit : RaycastHit;
         var roundpos : Vector3;
         
         if(Physics.Raycast(Firefrom.position, Firefrom.forward, hit))
         {
             //roundpos =
             Debug.Log(hit);
             roundpos = hit.point - Firefrom.forward.normalized * 0.05;
             roundpos *= 2.0;
             roundpos = Vector3(Mathf.Round(roundpos.x), Mathf.Round(roundpos.y), Mathf.Round(roundpos.z));
             roundpos /= 2.0;

             var Temp = Instantiate(currentbrick, roundpos , Quaternion.LookRotation(Vector3.zero));
             
             if(Input.GetKeyDown(KeyCode.W))
             {
                 Temp.tranform.position = Vector3(1,2,3);
             }
         }
     }
 }



The last part will not work, there is literaly no way to move the thing. (this isn't full script)

Comment
Add comment · Show 2
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 fafase · Dec 05, 2013 at 02:31 PM 0
Share

You need to show more of the script as you claim this is not all of it. Also, you need to tell the error or problem.

I would suspect that the instantiation happens in a method and you get that Temp does not exist in this scope.

avatar image applejuices · Dec 05, 2013 at 02:47 PM 0
Share
 var Firefrom : Transform;
 var currentbrick: GameObject;
 var finalbrick : GameObject;
 ;
 function Update () {
 if(Input.GetButtonDown("Fire1")){
 var hit : RaycastHit;
 var roundpos : Vector3;
 
 
 
 
 if(Physics.Raycast(Firefrom.position, Firefrom.forward, hit)){
 //roundpos = 
 Debug.Log(hit);
 roundpos = hit.point - Firefrom.forward.normalized * 0.05;
 roundpos *= 2.0;
 roundpos = Vector3($$anonymous$$athf.Round(roundpos.x), $$anonymous$$athf.Round(roundpos.y), $$anonymous$$athf.Round(roundpos.z));
 roundpos /= 2.0;
 
 
 var Temp = Instantiate(currentbrick, roundpos , Quaternion.LookRotation(Vector3.zero));
 
 if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.W)){
 
 }
 }
 }
 }
 

Cant belive I can not do this crap.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Dec 05, 2013 at 03:25 PM

Well your code can't work. Update is called once every frame. However this if statement is only true for one frame, the moment you press your fire button:

     if(Input.GetButtonDown("Fire1"))

So everything within the body of the is block is executed "once" the moment you press fire.

Inside the body you have another "button down" check for the "w" key, however it's nearly impossible that you press both keys at the exact same time. If you press w 10ms later the next frame the first if statement is false again.

It seems you're lacking of some basic control flow rules. From your script it's hard to tell what you actually want to do... You clamp the position to a multiple of 2, which is fine, but why do you want to set the position of the instantiated "brick" to a fix world position when you press a button?

Keep in mind that you can press fire multiple times which would instantiate multiple bricks. If you want to somehow "move" the brick with a key press, which brick do you want to move? the last created?

First you should be clear what you want to do and once that's clear you start coding it. If you can't explaint what you want to do, you can't code it!

Comment
Add comment · Show 4 · 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 applejuices · Dec 05, 2013 at 03:44 PM 0
Share

I know. But I have an idea of what I want to do. Only problem is, I cant ad a vector3 valse for some odd reason.

avatar image applejuices · Dec 05, 2013 at 03:46 PM 0
Share

meaning I can do all this, but Temp.transform.position += Vector3(1,1,1); wont work. er

avatar image stevethorne · Dec 05, 2013 at 07:38 PM 0
Share

That's intended @applejuices. If you want to move something use Temp.transform.Translate( Vector3( 1, 1, 1 ) );

avatar image Bunny83 · Dec 05, 2013 at 08:44 PM 0
Share

Your line:

     Temp.transform.position += Vector3(1,1,1);

works pretty well.

The problem is that this line is never executed, because in your code it would only execute when you press both keys at the exact same time, which would almost never happen.

You have "an idea" what you want to do, but you haven't told us your "idea". We told you why your code doesn't work, but we can't suggest a solution without knowing what you want. Try to explain what exactly should happen when you do what. $$anonymous$$eep in $$anonymous$$d to not use general terms like "the object should move". Which object? Again, if you press your fire button 2 or more times you have 2 or more objects in the scene. When you press the "W" key which object(s) should do what.

You're giving us a hard time to help you...

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

Read variable from txt to Vector3 1 Answer

My Vector3.Lerp is not working. Please look at my script. 2 Answers

Y value in Vector3 and Vector3.y not the same 1 Answer

Access 2 of the 3 components of Vector3 (Vector3.xy?) 2 Answers

Want to find the point straight below the controller 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