Answer the question
In order to leave comments, you need to log in
How to write a game using only scripts in Unity?
We started with a friend to make a game on Unity, only on scripts, that is, the minimum number of objects on the scene, only the camera and one object, which, as it were, launches the Main script, which should run everything else that is needed, and so on.
In general, the bottom line is this, I'm a little confused about how to write a game in general. To give an example, I create a script without MonoBehaviour like this:
using UnityEditor;
using UnityEngine;
namespace Assets.Scripts
{
public class Animal
{
public GameObject go = new GameObject("", typeof(CircleCollider2D), typeof(Rigidbody2D), typeof(SpriteRenderer));
public Animal()
{
go.name = "Animal";
go.GetComponent<Rigidbody2D>().gravityScale = 0f;
go.transform.position = new Vector3(0, 0);
go.transform.rotation = new Quaternion(0, 0, 0, 0);
Debug.Log(go.name);
}
public class Cat : Animal
{
public GameObject go = new GameObject("", typeof(CircleCollider2D), typeof(Rigidbody2D), typeof(SpriteRenderer));
public Cat()
{
go.name = "Cat";
go.GetComponent<Rigidbody2D>().gravityScale = 0f;
go.transform.position = new Vector3(0, 0);
go.transform.rotation = new Quaternion(0, 0, 0, 0);
Debug.Log(go.name);
}
}
}
Answer the question
In order to leave comments, you need to log in
1) Learn what prefabs are
2) You can do this. As well as hammering nails with a microscope.
And also read how inheritance is arranged, you clearly don’t understand this moment
There is such a plug-in for Unity3d - PlayMaker - www.hutonggames.com
It allows you to make games in Unity3d without direct programming by the so-called visual programming. It's similar to Blueprint in Unreal Engine.
But to be honest, I would still advise you not to do this, but to take it and start learning C# or javascript normally.
Perhaps the description of my game will help you - I'm also a beginner, but I've been doing it for more than six months, the general architecture has more or less settled down. The essence of the game is inspired by the Space Rangers - the universe, consisting of stars, the main place of action is star systems, the game takes place inside them. Accordingly, before the start of the game, there are practically no objects - only dummies and scripts for them, and of course the UI. When you start the game from a save (or randomly generated) the universe is an array of stars, which in turn contain planets, belts, etc. This data is not related to MonoBehaviour in any way, just a static array (List actually, but not the point). At the start of the game, again, the location of the player, information about his ship is taken from the save, and in accordance with this
1) The current system spawns: the sun, planets (there is a planet prefab, when spawning, a script hanging on it imposes a randomly generated texture, and another script places it in space in accordance with the specified orbit parameters), etc.
2) The player spawns (and other players in the future)
Thus, the scene contains only the player's dummy with scripts hung on it and UI objects. Everything else is created as the game progresses.
Of course, you can write in the way you suggest: create everything in code, and manage only one object. Probably, for some cases this will be a reasonable solution (I don’t know what your task is). For your case, you can create objects in advance, save them in prefabs (it's very simple), and then create the required number of objects from the code and do whatever you want with them. In any case, an object created from a prefab (for example, using the Instantiate method) will have a minimal set of mechanisms for manipulating it. At a minimum, any object has a Transform component. Also, various other components can be attached to any object from the code in the process (and also unhooked if necessary). All this is possible. The main thing is to understand whether such an approach is really justified. If you think,
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question