Hi everyone, I've been able to play a bit with the Unity editor and I've been researching how to program some useful things for future Map Mods. Soon I will be able to share with all these advances. However, I run into a problem, while developing something that I consider fundamental in the design of maps and adventures for SimplePlanes... It is a script that serves to detect when a player enters a predetermined area and execute a series of predetermined actions. In this case, when the player passes through the delimited area, an enemy plane appears, controlled by the AI of the game. I have been searching and inquiring a lot in the manuals and guides available on the Internet and have found several ways to do it, however, I can not get it to work properly. I am convinced that there is some way, and I am close to solving the problem, but I have not found it yet. In this article I publish the experience in the development of this Script and the problems that I am facing.
Situation / context
I am carrying out the tests on a new map that reproduces the Falklands Islands. The stage has been taken from the actual heightmaps of the area and scaled so that it has approximate dimensions to the real place. The idea is that when the player's plane passes through a certain area, an enemy plane appears controlled by the AI of the game. That area for the trigger was named and tag as greenzone and I've recreated it with a transparent green cube. On the other hand I created an AI Aircraft object, whose label, name and ID is "enemy101" It is a Mig-21 test aircraft that I hope to publish soon.
Fig1. Essential objects for trigger test
With these two objects prepared, I created 2 codes in CSharp/C#. A code that will act as a trigger for the green cube. The idea is that when the player enters the area of the cube, which we have called "greenzone", the object enemy101 appears in the game. I have called this code "miko3TriggerPlane". The other code "miko4EnemyInactive" should serve so that the object of the game called "enemy101" is inactive until the trigger of the "greenzone" is activated. Actually what we are looking for is that the element "enemy101" is hidden until the event is triggered.
The script
Let's take a look at the code...
miko3TriggerPlane
In this code the variables of the player and the "enemy101" which is the AI Aircraft Spawner of SimplePlanes are declared. Then we try to say that at the beginning of the game the object "enemy101" is inactive. For that we use the "SetActive (false)" function. Next, we use the "OnTriggerEnter" function to determine that when the player enters the cube area the action we want is triggered, which is to activate the "enemy101". For that we use the "SetActive (true)" function again. To indicate that the user enters the collision space of the "greenzone", it indicates "Collider other" and the condition "other.tag == Player". However, I have seen this part expressed in several ways, for example ... (Collider player)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class miko3TriggerPlane : MonoBehaviour {
public GameObject player;
public GameObject enemy101;
void Start() {
enemy101.SetActive(false);
}
void OnTriggerEnter(Collider other) {
if (other.tag == "Player") {
enemy101.SetActive(true);
}
}
}
fig2. miko3TriggerPlane.cs
miko4EnemyInactive
In the tests that I have done, the enemy101 kept appearing even though in the code "miko3TriggerPlane.cs" I have expressly indicated that it is inactive. So I thought about adding this code "miko4EnemyInactive" to try to get it, however the attempts did not work.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class miko4EnemyInactive : MonoBehaviour{
public GameObject enemy101;
void Start(){
enemy101.SetActive(false);
}
}
fig3. miko4EnemyInactive.cs
The problem
I'm pretty sure that the "void OnTriggerEnter ()" function has to be used in this case. However, I do not know what the player's tag or identifier is in SimplePlanes. Maybe it's "player". On the other hand, I do not know how to make the enemy101 only appear when the player passes through the "greenzone". Surely there are many things that are escaping me. If someone can help me or know the solution, I would appreciate it if you could help me with this problem. Thank you very much in advance.
Have you ever completed the 6 puzzles in Quick Draw
@Kimcotupan15 I already did
@Ryn176 use structural wings and XML mod it to have a control surfaces
@JohnnyBoythePilot yes this is the idea, i making a map mod as example for all community
If this works out fine you should make more combat theater-based maps like Vietnam or the Middle East.
I need an unrelated help
My plane kept wobbling whenever I reached 1400 MPH
So, can anyone help?
please
Not too long till we have player made campaigns!!
Trigger was the closest
You're welcome!
@FairFireFight i will check your problem...
Y'all here scripting 'n' sh!t mean while i'm stuck with This error :'(
@JamesBleriot Roger that!
@mikoyanster Share it with @AndrewGarrison
Can you put a spawn box over skypark navy fleet and by DerekSp and uss beast and then put the whole project in a zipfile for me? Pleeeaaazzz
Good for Pretty much dogfights or a SimplePlanes film, Great!
@MisterT i will share with all community ;-)
Awsome !
@MOPCKOEDNISHE @Aerofy
@MisterT @DuckMint @Chancey21
@Lahoski107 Thank you!