Question by
unity_yCl73dUSuMVAzg · May 20, 2020 at 02:57 PM ·
c#unity 2d
Instanciated objects can only be seen if they were instanciated while looking to the left.
What i mean by this, is the fact that the sprite is instanciated everytime, however, i can only see them if I instancate them while looking to the left:
Here are my scripts: (I know they are bad) using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Movement : MonoBehaviour
{
public int moveSpeed = 2;
public int jumpSpeed = 2;
public Rigidbody2D rb;
public int onGround = 2;
public GameObject parent;
void Update()
{
Jump();
Rotate();
}
// Update is called once per frame
void FixedUpdate()
{
Vector3 movement = new Vector3(Input.GetAxis("Horizontal") , 0 , 0);
transform.position += movement * Time.fixedDeltaTime * moveSpeed;
}
public void Jump()
{
if (Input.GetButtonDown("Jump") && onGround > 0)
{
onGround--;
rb.AddForce(new Vector2(0f , jumpSpeed), ForceMode2D.Impulse);
}
}
void Rotate()
{
if (Input.GetKeyDown("d"))
{
transform.rotation = new Quaternion(0 , 0 , 0 , 0);
parent.transform.GetChild(1).gameObject.transform.rotation = new Quaternion(0 , 0 , 0 , 0);
}
if (Input.GetKeyDown("a"))
{
transform.rotation = new Quaternion(0 , 180 , 0 , 0);
parent.transform.GetChild(1).gameObject.transform.rotation = new Quaternion(0 , 180 , 0 , 0);
}
if (Input.GetKeyDown("a") && Input.GetKeyDown("d"))
{
transform.rotation = new Quaternion(0 , 0 , 0 , 0);
}
}
}
Shooting:
using UnityEngine;
public class Shoot : MonoBehaviour
{
public Transform firepoint;
public GameObject bullet;
void Update()
{
if(Input.GetButtonDown("Fire1"))
{
BulletCommitShoot();
}
}
public void BulletCommitShoot()
{
Instantiate(bullet , firepoint.position , firepoint.rotation);
}
}
Ground Checking script:
using UnityEngine;
public class CheckGround : MonoBehaviour
{
public Rigidbody2D rb;
GameObject player;
void Start()
{
player = gameObject.transform.parent.gameObject;
}
private void OnCollisionEnter2D(Collision2D collision) {
if (collision.collider.tag == "GTL")
{
player = gameObject.transform.parent.gameObject;
player.GetComponent<Movement>().onGround = 2;
}
}
}
Sorry for having long question. Yeah
Comment
Your answer
Follow this Question
Related Questions
switch between 5 Ui icons by pressing a button 0 Answers
Shooting an instantiated missile the way a object is facing. 0 Answers
How do I make a scrollbar for the camera? 0 Answers
How to add more UI elements to Dropdown OptionData except default string and sprite values in Unity? 0 Answers
Make Jump Fish game 1 Answer