Hello guys, I don’t actually have the two scripts to show right now because I’m walking to work now. Although what I and my friend are trying to do is to send a GameObject variable to a different script to be able to know what floor the character is stepping on (there will be 100’s of floors so we don’t want to hardcode it). We were trying to use GameObject.Find and use the GameObject variable as the string of what we want it to find. Although that doesn’t work.
Thanks in advance guys.
(I got home here are the scripts)
CAMERA MOVEMENT:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraMovement : MonoBehaviour {
private Vector2 velocity; //required for calculations
public float timer_y; //Timer for camera smoothing
public float timer_x;
public GameObject player;
public GameObject floor;
public float floorMargin; //Margin to adjust y axis on camera
private PlayerMovement playerMovement;
void Awake () {
playerMovement = GetComponent ();
}
void Start () {
player = GameObject.FindGameObjectWithTag (“Player”);
}
void Update () {
//floor = GameObject.Find (playerMovement.floorTag.ToString());
floor = playerMovement.floorTag;
}
void FixedUpdate () {
float position_x = Mathf.SmoothDamp (transform.position.x, player.transform.position.x, ref velocity.x, timer_x);
float position_y = Mathf.SmoothDamp (transform.position.y, (floor.transform.position.y + floorMargin), ref velocity.y, timer_y);
transform.position = new Vector3 (position_x, position_y, -1f);
}
}
PLAYER MOVEMENT:
void OnTriggerEnter2D (Collider2D other) {
floorTag = other.gameObject;
}