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 CobbledGames · Jan 22, 2019 at 10:20 PM · 2dplayertriggersheightground

Unity 2D how to simulate height using triggers and a variable

Hello

I would like to know if anyone can come up with a solution to this;

I'm trying to produce a 2D game, but want to simulate height. I have a number variable that is assigned to a ground object that has a trigger attached to it.

A player game object is supposed to check whether the player is in one of these ground height triggers, and if the player is in one of these triggers, it assigns the height number of the ground object to the player's height number.

Essentially If the player enters a ground with a level of 1 it's ground level is 1 if it enters a ground with a level of 2 it's ground level is 2 etc.

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

2 Replies

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

Answer by CobbledGames · Jan 23, 2019 at 11:13 AM

The ground variable is set up in it's own script, the player's variable is set and the check for the ground triggers is set in another. I might need a little more guidance for the method of getting the collider and Var. I'll see what I can do though.

Comment
Add comment · Show 6 · 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 CobbledGames · Jan 23, 2019 at 11:28 AM 0
Share

No it seems I don't have this figured out. $$anonymous$$ay I ask how to to do this: "you would be able to access the collider.gameObject.getcomponent of that script and access the var and just assigned it in your script."

avatar image xxmariofer CobbledGames · Jan 23, 2019 at 11:39 AM 0
Share

that completly depends of your code, can you share it so i can guide you?

avatar image CobbledGames xxmariofer · Jan 23, 2019 at 06:58 PM 0
Share

Ground level assigning script:

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class GroundLvlAssign : $$anonymous$$onoBehaviour { public float SetGroundLvl = 1f; public Collider2D m_GroundCollider;

}

Checking Script:

using System.Collections; using System.Collections.Generic; using UnityEngine.UI; using UnityEngine;

public class PlayerStatistics : $$anonymous$$onoBehaviour {

 public float m_PlayerGroundLvl  = 1; //What level of ground object is on.
 GroundLvlAssign m_GroundLvlAssign; //GroundlvlNumberScript
 
 public Collider2D m_CenterOfBalance;
 
 void OnTriggerEnter2D (Collider2D ground)
 {
     
 }

}

Where SetGroundLvl is the Height level of the ground object, GroundCollider is it's collider and CenterOfBalance is the collider on the player object that is used for checking the ground level. Some of the 2nd script is missing because it isn't relevant to the question.

Show more comments
avatar image
0

Answer by xxmariofer · Jan 22, 2019 at 11:10 PM

Well, the solution is in your own question, just ontriggerenter2d method for getting the event, you said you have a number variable assigned to the ground, how is that var assigned? is inside the script? you would be able to access the collider.gameObject.getcomponent of that script and acces the var and just assigned it in your script.

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

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

A 2D Character Controller with Rigidbody2D.AddForce 2 Answers

Need your IDEAS!! (Players building their own base) 2 Answers

Problem with a multi-jump script ( C# ) 1 Answer

My enemy doesn't die when my player attacks, when I try to click space bar, the player is hitting the enemy, but the enemy only acknowledges the damage after five or more hits, any advice? 1 Answer

Can the new ParticleSystem Trigger Module access the particle's collision collider? 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