Search Unity

Giving $100 USD if somebody could help me solve this problem.

Discussion in 'Commercial: Job Offering' started by snoots, Jun 12, 2021.

  1. snoots

    snoots

    Joined:
    Mar 14, 2021
    Posts:
    7
    I've just about had it with this bug. It's been bothering me for days and I can't continue to work on my game without solving it.

    So, this is my last-ditch effort, I don't want to give up on this small project, but if I wouldn't be able to solve the bug, I won't have any other choice.

    I will be giving away $100 USD (via PayPal) to anyone who could help solve this for me. I've browsed all over google trying to find out how to fix it and there are more bugs than solutions on this.

    The bug is that I can't use scripts with an instantiated game object.

    All I am trying to do is make a simple script that spawns a tree branch prefab, and be able to change it's position on a different script.

    If you think you can solve it, drop your PayPal email and give it a shot (or if you aren't comfortable with dropping your email in public you can always just start a conversation with me). Whom ever solves the solution first gets the reward.

    Here's the script:

    BranchSpawner.cs
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class BranchSpawner : MonoBehaviour
    6. {
    7.  
    8.     public GameObject TreeBranch;
    9.  
    10.     // Start is called before the first frame update
    11.     void Start()
    12.     {
    13.         spawnEnemy();
    14.     }
    15.  
    16.     void spawnEnemy() {
    17.         GameObject newBranch = Instantiate(TreeBranch);
    18.         newBranch.transform.position = new Vector3(1.5f,10,0);
    19.     }
    20.  
    21.     // Update is called once per frame
    22.     void Update()
    23.     {
    24.        
    25.     }
    26. }
    27.  
    MainScript.cs
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine.SceneManagement;
    4. using UnityEngine;
    5.  
    6. public class MainScript : MonoBehaviour
    7. {
    8.  
    9.     private float branchDownNumb;
    10.     public GameObject treeBranch;
    11.     private bool playerFlipped;
    12.  
    13.     // Start is called before the first frame update
    14.     void Start()
    15.     {
    16.         branchDownNumb = 20;
    17.         playerFlipped = false;
    18.     }
    19.  
    20.     private void OnTriggerEnter2D(Collider2D collision) {
    21.         if(collision.name == "TreeBranch(Clone)") {
    22.             SceneManager.LoadScene("GameEndScene");
    23.         }
    24.     }
    25.  
    26.     void lumberJackController() {
    27.         if(treeBranch == null){
    28.             return;
    29.         }
    30.         if(Input.GetKeyDown(KeyCode.LeftArrow)) {
    31.             treeBranch.transform.Translate(new Vector3(0,-branchDownNumb,0));
    32.             ScoreScript.scoreValue += 1;
    33.             playerFlipped = false;
    34.         }
    35.         if(Input.GetKeyDown(KeyCode.RightArrow)) {
    36.             treeBranch.transform.Translate(new Vector3(0, -branchDownNumb, 0));
    37.             ScoreScript.scoreValue += 1;
    38.             playerFlipped = true;
    39.         }
    40.     }
    41.  
    42.     // Update is called once per frame
    43.     void Update()
    44.     {
    45.  
    46.         Vector3 characterScale = transform.localScale;
    47.        
    48.         lumberJackController();
    49.  
    50.         if(playerFlipped == false) {
    51.             transform.position = new Vector3(-1.5f, -2, 0);
    52.             characterScale.x = 6.25f;
    53.         } else if(playerFlipped == true) {
    54.             transform.position = new Vector3(1.5f, -2, 0);
    55.             characterScale.x = -6.25f;
    56.         }
    57.  
    58.         transform.localScale = characterScale;
    59.     }
    60. }
    61.  
    So here's what the script does. It spawns the branch prefab in the desired spawn location, but the transform.Translate doesn't change the tree branch's position, It stays in the same place. It doesn't give me any errors, it doesn't give me any warnings.

    I've added the tree branch prefab into the public GameObject in the tree branch spawner script, and added the same prefab as well into the public GameObject for the main script.

    I am completely lost, and I have no idea what to do. I'm still new to unity, and I figure that if I don't learn how to solve this bug NOW, I will have the same problems with it in the future.

    Thank you for your time, and I hope one of you could help me.
     
    jtok4j likes this.
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,487
    This is not appropriate for the 2D forums.

    You should post it here.

    I can move it for you if you like.
     
  3. snoots

    snoots

    Joined:
    Mar 14, 2021
    Posts:
    7
    woops, my apologies. I would greatly appreciate if you could move it!
     
  4. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,073
    Your script is a total mess. I know what you want to do and what is the problem but the script is so bad that it needs total rewrite.

    It's not working for you because MainScript is setting location of itself. So you would have to put it on a prefab.
    At the same time you got some lumber jack controller that is setting position of prefab and not a GameObject that originated from it.
     
    Last edited: Jun 12, 2021