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 mrgohut · Apr 07, 2014 at 09:23 PM · camerarotatecube

Cube doesn't follow camera

 using UnityEngine;
 using System.Collections;
 
 public class Build : MonoBehaviour {
 
     public GameObject cube1;
     public GameObject cube2;
     public GameObject cube3;
     public GameObject cube4;
 
     public bool Cube1;
     public bool Cube2;
     public bool Cube3;
     public bool Cube4;
 
     public bool block;
 
     private GameObject newCube;
 
     public bool Active;
     public bool warning;
     public bool clear;
 
     public Inventory check;
 
     public string warningText;
 
     void Start () 
     {
 
     }
     
     void Update () 
     {
         if(Input.GetKeyDown(KeyCode.B) && !Active && !block)
         {
             if(check.woodCount > 0)
             {
                 if(Cube1)
                 {
                     newCube = Instantiate(cube1, new Vector3(transform.position.x,10,transform.position.z) + transform.forward * 4.0f, transform.rotation) as GameObject;
                     Active = true;
                     newCube.transform.parent = Camera.main.transform;
                     //check.woodCount -= 10;
                     //cube.rigidbody.isKinematic = true;
                     block = true;
                 }
                 if(Cube2)
                 {
                     newCube = Instantiate(cube2, new Vector3(transform.position.x,10,transform.position.z) + transform.forward * 4.0f, transform.rotation) as GameObject;
                     Active = true;
                     newCube.transform.parent = Camera.main.transform;
                     //check.woodCount -= 10;
                     //cube.rigidbody.isKinematic = true;
                     block = true;
                 }
                 if(Cube3)
                 {
                     newCube = Instantiate(cube3, new Vector3(transform.position.x,10,transform.position.z) + transform.forward * 4.0f, transform.rotation) as GameObject;
                     Active = true;
                     newCube.transform.parent = Camera.main.transform;
                     //check.woodCount -= 10;
                     //cube.rigidbody.isKinematic = true;
                     block = true;
                 }
                 if(Cube4)
                 {
                     newCube = Instantiate(cube4, new Vector3(transform.position.x,10,transform.position.z) + transform.forward * 4.0f, transform.rotation) as GameObject;
                     Active = true;
                     newCube.transform.parent = Camera.main.transform;
                     //check.woodCount -= 10;
                     //cube.rigidbody.isKinematic = true;
                     block = true;
                 }
             }
             else
             {
                 warningText = "You don't have wood !";
                 warning = true;
             }
         }
         if(Input.GetKeyDown(KeyCode.V) && Active && block)
         {
             newCube.transform.parent = null;
             //cube.rigidbody.isKinematic = false;
             Active = false;
             clear = true;
             block = false;
         }
         if(clear)
         {
             Cube1 = false;
             Cube2 = false;
             Cube3 = false;
             Cube4 = false;
             clear = false;
         }
     }
 }

My problem: I can spawn cube, it spawn in fron of me, 10 forward like in script, but after that when i move my character, cube doesn't follow ;/ it just rotate with me, nothnig else. I have First Person Character from Sample Asstes .

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
Best Answer

Answer by perchik · Apr 07, 2014 at 09:25 PM

Right, that's what the code you have does. It instantiates a cube at a position, but doesn't do anything to update it's position.

After checking all the inputs in Update, you need to add something like this:

 if(Cube1)
 {
      cube1.transform.position = transform.position + transform.forward * 4.0f;
 }

which will set the cube's position to the current position plus 4 units forward.

Comment
Add comment · Show 1 · 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 mrgohut · Apr 07, 2014 at 09:40 PM 0
Share

Thanks, that's strange, because when i had character from standard assets (basic import) everything worked fine :<

But thanks, it work :)

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

22 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 avatar image avatar image avatar image

Related Questions

Character controls seen in Amnesia 4 Answers

Sprinting camera movement? (C#) 1 Answer

Click on collider to rotate camera 1 Answer

One wall cube in the Scene is not shown by Camera in Game view 0 Answers

RTS type of camera 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