Hi, I’m pretty new to Unity. I’m trying to practice by remaking the game pop the lock and i want it to be so when you press space while the line is on the dot it’ll move somewhere else
heres my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class space : MonoBehaviour
{
public Collider2D lineCol;
public Collider2D dotCol;
public GameObject dot;
void Update()
{
if(Input.GetKeyDown("space")){
Debug.Log("spaced");
if(lineCol.IsTouching(dotCol)){
//this part doesn't print
Debug.Log("WORK!!");
dot.GetComponent<spawn>().Spawn();
}
}
}
}
and heres my spawn script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class spawn : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
Spawn();
}
public void Spawn(){
float randomRot = Random.Range(0, 360);
Debug.Log(randomRot);
transform.eulerAngles = new Vector3(0, 0, randomRot);
}
}
let me know if you need more photos or anything