Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Codelyy · Mar 20, 2016 at 03:51 PM · guicolliderboxborder

Simply creating a box

For some reason I just can't figure out how to do this but basically I'm trying to make a simple box that the player can be placed in too but can't escape due to a collider/border around the box with the ability to be able to resize the box in code while also changing the size/placement of the collider/border. If you want to see an example of what I mean then look at battles in undertale as I'm basically trying to recreate the same thing within unity. Skip to 1:35 of the video: https://www.youtube.com/watch?v=6RL6JcEHw2U

I'm referring to the simple black box with a white border around it that can be resized in code. I basically want to recreate that in unity still being able to resize it in code and have a collider of some kind around the white border so the player can't escape the box but I'm not sure how to do it. Should I make a sprite of the box? or use GUI to create the box and be able to resize, have no idea...

I would love if someone would be able to help me out?

Thanks

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 BlockFade · Feb 06, 2017 at 06:56 PM

@Codelyoko363

  • 1.Put the player sprite in the middle of where you want your bullet box to be with a layer order of 2 or higher.

  • 2.right click on your project window and create a square sprite and name it "Black".

  • 3. repeat step 2 but name it "White".

  • 4. place the Black sprite where the player sprite is, then set the layer order to -1 or 0 then rescale it to where you'd like

  • 5. Place White sprite on each edge of the Black sprite then rescale it to wear you'd like it.

  • 6. Add a RigidBody2D to each White sprite. Then set the mode to Kinematic.

  • 7. Add a BoxCollider2D to each White sprite.

  • Create a new C# Script, name it PlayerMovement. Then paste the following code:
  •  using UnityEngine;
     // If this is wrong, sorry I was at school instead of at my computer.
     public class PlayerMovement: MonoBehaviour {
     public Transform Player;
     void Update() {
     if(Input.GetKey(KeyCode.LeftArrow)) {
     if(Input.GetKey(KeyCode.UpArrow)) {
      Player.position = new Vector3(Player.position.x - 1, Player.position.y + 1, Player.position.z);
     }
     else if(Input.GetKey(KeyCode.DownArrow)) {
      Player.position = new Vector3(Player.position.x - 1, Player.position.y - 1, Player.position.z);
     }
     
      Player.position = new Vector3(Player.position.x - 1, Player.position.y, Player.position.z);
     }
     else if(Input.GetKey(KeyCode.RIghtArrow)) {
     if(Input.GetKey(KeyCode.UpArrow)) {
      Player.position = new Vector3(Player.position.x + 1, Player.position.y + 1, Player.position.z);
     }
     else if(Input.GetKey(KeyCode.DownArrow)) {
      Player.position = new Vector3(Player.position.x + 1, Player.position.y - 1, Player.position.z);
     }
     
      Player.position = new Vector3(Player.position.x + 1, Player.position.y, Player.position.z);
     }
     else if(Input.GetKey(KeyCode.UpArrow)) {
      Player.position = new Vector3(Player.position.x, Player.position.y + 1, Player.position.z);
     }
     else if(Input.GetKey(KeyCode.DownArrow)) {
      Player.position = new Vector3(Player.position.x, Player.position.y, - 1, Player.position.z);
     }
     }
     }
    

    If this is wrong, sorry I was at school instead of at my computer.

  • Assign the player sprite to the Player varible and add a BoxCollider2D to your Player sprite!
  • Now your done!

    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

    65 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 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 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

    How to instantiate (MonoBehaviour) script multiple times and call void? 1 Answer

    RTS Click Drag Selection box not working with GUI canvas 1 Answer

    How to add text to a box ? 2 Answers

    Mario Kart style power ups 0 Answers

    Box cast issue 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