Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 kozlovskiygk · Nov 02, 2021 at 09:54 AM · unityeditorscalingwalls

Auto growing / scaling - C#

Hi guys,

The situation is following: I've got a player in the room. The player can move and jump. Each time a player jumps up and gets higher- walls should grow up with him, not to let him ever reach the top.

Can anyone recommend, how to scale walls properly based on player position? I have tried the method below, but it's too complicated and doesn't work properly, making me thinking, that there should be some clever and easy solution....

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

public class WallGrowing : MonoBehaviour {

 public GameObject LeftWall;
 public GameObject RighWall;
 public GameObject FrontWall;
 public GameObject BackWall;

 public GameObject UpperLimit;

 public GameObject player;

 private float PlayerPositionY;
 private float UpperLimitPositionY;
 private float LeftWallCurrentScaleY;

 private float difference;

 private float ULSSpawnPositionX;
 private float ULSSpawnPositionY;
 private float ULSSpawnPositionZ;

  


 private Vector3 ScaleChange = new Vector3(0.01f, 0, 0);

 // Start is called before the first frame update
 void Start()
 {
     
 }

 // Update is called once per frame
 void Update()
 {
     //*
     SnapCurrentHeight();
     HeightChange();
     UpperLimitSpawn();

     Debug.Log(PlayerPositionY + "  " + UpperLimitPositionY + "  " + difference);
     //*/
 }
 //*
 void UpperLimitSpawn()
 {

     ULSSpawnPositionX = UpperLimit.transform.position.x;
     ULSSpawnPositionX = UpperLimit.transform.position.y;
     ULSSpawnPositionX = UpperLimit.transform.position.z;

     if (difference < 3)
     {
         float ULSSpawnPositionYNew = ULSSpawnPositionY + 5;
         UpperLimit.transform.position = new Vector3(ULSSpawnPositionX, ULSSpawnPositionYNew, ULSSpawnPositionZ);
     }
 }

 void SnapCurrentHeight()
 {
     PlayerPositionY = player.transform.position.y;


     UpperLimitPositionY = UpperLimit.transform.position.y;

     LeftWallCurrentScaleY = LeftWall.transform.localScale.x;
     

     difference = UpperLimitPositionY - PlayerPositionY;
 }


 void HeightChange()
 {
     if (difference < 3)
     {
         WallScaneTransformPlus();
     }

     if (difference > 2 && difference < 5)
     {
         WallScaneTransformPlusMinus();
     }

 }

 void WallScaneTransformPlus()
 {
     LeftWall.transform.localScale += Vector3.up + (ScaleChange/2);
     LeftWall.transform.Translate(Vector3.right / 45);
 }

 void WallScaneTransformPlusMinus()
 {
     LeftWall.transform.localScale += Vector3.up - (ScaleChange/2);
     LeftWall.transform.Translate(Vector3.left / 45);
 }

// */ }

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 kozlovskiygk · Nov 02, 2021 at 10:51 AM

If somebody is following, I am trying another way now: I have attached walls to the player, so they are constantly moving and it looks cool + the idea is to instantiate walls again and again when some Y is reached. But this is to be pollished.

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

public class WallGrowing : MonoBehaviour {

 public GameObject LeftWall;
 public GameObject RighWall;
 public GameObject FrontWall;
 public GameObject BackWall;

 public GameObject UpperLimit;

 public GameObject player;

 public float playerPositionY;


 public float oldlWallYposition; 

 private float newWallXposition;
 public float newWallYposition;
 private float newWallZposition;


 public GameObject[] wallPrefab;




 // Start is called before the first frame update
 void Start()
 {
     oldlWallYposition = LeftWall.transform.position.y;
     newWallXposition = LeftWall.transform.position.x;
     newWallZposition = LeftWall.transform.position.z;
 }

 // Update is called once per frame
 void Update()
 {
     SnapPlayerPosition();
     SpawnChecker();
     Debug.Log(playerPositionY);


 }

void SpawnChecker() { if (playerPositionY > 10) { WallSpawn(); } }

void SnapPlayerPosition() {

     playerPositionY = player.transform.position.y; 
 }

void WallSpawn() {

     newWallYposition = oldlWallYposition + 10;
       


     Vector3 spawnPosWall = new Vector3(newWallXposition, newWallYposition, newWallZposition);

     Instantiate(wallPrefab[0], spawnPosWall, wallPrefab[0].transform.rotation);
     oldlWallYposition = newWallYposition;
 }
   

}

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 kozlovskiygk · Nov 02, 2021 at 12:11 PM 0
Share

and the final solution is this: (thank to all of you, lol :D)

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

public class WallGrowing : MonoBehaviour {

 public GameObject LeftWall;
 public GameObject RighWall;
 public GameObject FrontWall;
 public GameObject BackWall;

 public GameObject UpperLimit;

 public GameObject player;

 public float playerPositionY;


 public float oldlWallYposition; 

 private float newWallXposition;
 public float newWallYposition;
 private float newWallZposition;


 public GameObject[] wallPrefab;

 private float level = 0;

 public float $$anonymous$$X = 5f;
 public float x1;



 // Start is called before the first frame update
 void Start()
 {
     oldlWallYposition = LeftWall.transform.position.y;
     newWallXposition = LeftWall.transform.position.x;
     newWallZposition = LeftWall.transform.position.z;
 }

 // Update is called once per frame
 void Update()
 {
     SnapPlayerPosition();
     levelChecker();
     x1 = player.transform.position.y;
     Debug.Log(x1 +" " + "$$anonymous$$X=" + $$anonymous$$X + " " + "level=" + level);



 }

void levelChecker() { if (x1 > $$anonymous$$X) { level += 1; $$anonymous$$X = $$anonymous$$X + 5; WallSpawn(); } }

void SnapPlayerPosition() {

     playerPositionY = player.transform.position.y; 
 }

void WallSpawn() { newWallYposition = oldlWallYposition + 5; Vector3 spawnPosWall = new Vector3(newWallXposition, newWallYposition, newWallZposition);

     Instantiate(wallPrefab[0], spawnPosWall, wallPrefab[0].transform.rotation);
     oldlWallYposition = newWallYposition;
 }
   

}

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

173 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

Related Questions

Unity Starting with White Screen 0 Answers

Value doesn't change in game when updated. 2 Answers

How to Fix my Unity? 0 Answers

Unity wont install any versions? 0 Answers

How to deal with 10,000s immobile gameobjects at once? 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