- Home /
Question by
Azmo96 · Dec 21, 2021 at 01:31 PM ·
spawning problems
How can i put scene objects into prefab Transform?,How do i place a scene object in a prefab Transform?
I am trying to learn unity and ia wanted to make a little game in ehich you can do spells and magic but I cant spawn a spell in the correct direction. Here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FireBallSpell : MonoBehaviour
{
public float speed = 50;
public Transform player;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
transform.rotation = player.transform.rotation;
Vector2 input = new Vector2(1,0);
Vector2 direction = input.normalized;
Vector2 velocity = direction * speed;
Vector2 moveAmount = velocity * Time.deltaTime;
transform.Translate(moveAmount);
}
}
This one is the fireball
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerSpells : MonoBehaviour
{
public GameObject fireBall;
public GameObject parent;
// Update is called once per frame
void Update()
{
Vector2 localpos = parent.transform.position;
if (Input.GetKeyDown(KeyCode.E))
{
Instantiate(fireBall);
fireBall.transform.position = localpos;
}
}
}
And this is on the player. I am using Visual Studio 2022 to code.
Comment
Your answer
Follow this Question
Related Questions
How to spawn cubes on mouse position 1 Answer
UNET: PlayerPrefab's `Start()` is being called before play scene's `Awake()` 0 Answers
Instantiating unique Prefabs to unique child objects in C# 3 Answers
How to respawn player car in war track 1 Answer
Spawning 2 players at the start of the game when it should not 0 Answers