How to implement a firebreathing mechanic in a 2D scroller
Hello there, I'm new to scripting and coding. I'm making my second solo game, and I had some questions about where to start with this.
The game is a 2D side scroller, and the player has a firebreathing mechanic when you press space. I've already managed to rig space to trigger the flame image to show up, but how do I make it spawn from my main player and stay there? Currently it just appears, but as the player automatically moves forward, the flame image stays in the same place.
What it looks like when the player moves forward
I looked at a simple bullet tutorial to get started. Can someone point me towards some other relevant tutorials? The ones I'm finding seem to be more targeted towards 3D, or for more advanced programmers. Just in case, here's the code I used.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Firebreathing : MonoBehaviour {
public GameObject Fire;
public Transform FireSpawn;
void Update () {
if (Input.GetKeyDown(KeyCode.Space))
{
BreatheFire();
}
}
public void BreatheFire()
{
var flame = (GameObject)Instantiate (Fire, FireSpawn.position, FireSpawn.rotation);
Destroy(flame, .5f);
}
}
Your answer
Follow this Question
Related Questions
How to write a script for an existing button 1 Answer
Controller / movement script rotate while moving HELP 0 Answers
How to make a proper Drag&Drop (any GameObject) for the Hololens (Unity3D) 0 Answers
I need help with my scripts! 1 Answer
How would you move from a array like from [2] to [3] or backwards like [2] to [1] 2 Answers