How to make script communication work in Unity

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Circle : MonoBehaviour
{
[SerializeField]
private float _radius = 0f;
// Start is called before the first frame update
void Start()
{
Debug.Log($"Circumference of {_radius}: " + GetCircumference());
Debug.Log($"Diameter of {_radius}: " + GetDiameter());
}
// Update is called once per frame
void Update()
{

}
float GetCircumference()
{
return 2 * 3.14f * _radius;
}
float GetDiameter()
{
return _radius * 2;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Display : MonoBehaviour
{
[SerializeField]
private Text _radiusText;
[SerializeField]
private Text _circumferenceText;
[SerializeField]
private Text _diameterText;
// Start is called before the first frame update
void Start()
{
//Display circle details in text UI
}
// Update is called once per frame
void Update()
{

}
}
void Start()
{
//Display circle details in text UI
Circle circle = GetComponent<Circle>();
if (circle != null)
{
_radiusText.text = "Radius: " + _radius ;
_circumferenceText.text = "Circumference: " + circle.GetCircumference();
_diameterText.text = "Diameter: " + circle.GetDiameter();
}
}

public class Circle : MonoBehaviour
{
/* REDACTED */
public float GetCircumference()
{
return 2 * 3.14f * _radius;
}
public float GetDiameter()
{
return _radius * 2;
}
public float GetRadius()
{
return _radius;
}
}
void Start()
{
//Display circle details in text UI
Circle circle = GetComponent<Circle>();
if (circle != null)
{
_radiusText.text = "Radius: " + circle.GetRadius() ;
_circumferenceText.text = "Circumference: " + circle.GetCircumference();
_diameterText.text = "Diameter: " + circle.GetDiameter();
}
}

--

--

--

I love game design and development.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Cracking the Coding Interview

Modern way of requesting Permission in Android

Building a bare-metal validator for Solana

READ/DOWNLOAD#! C# 7.0 in a Nutshell: The Definitive Reference FULL BOOK PDF & FULL AUDIOBOOK

Spring Boot Profiles

Razor- the next generation bare-metal provisioning software

Best Front End Development Languages

The Startup CTO’s Guide to Ops (3 of 3): A Minimal Production and Deployment Setup

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jaime

Jaime

I love game design and development.

More from Medium

3D Modeling 101: Comprehensive Beginners Guide — Wow-How Studio — Video Production, 2D & 3D…

Adding Audio: Making the Characters Speak! (Game Dev Day 56)

Display Random Cat Image from an API

How to stick decals on the Spatial Mesh of Hololens2