Referencing another script error/problem
I am trying to reference another script for my game Pong 2D this is the Ball script for the game
At the line "TriggerEvent = RightSideScene.GetComponent(TriggerEvent)();" I get the error "Argument1: Can not convert 'RightSideScene' to 'System.Type'
At the line "RightSideScene.TriggerEvent(sceneManager);" I get the error "'GameObject' does not contain a definition for 'TriggerEvent' accepting a first argument of type 'GameObject' could be found (are you missing a directive or a assembly reference"
public GameObject RightSideScene;
RightSideScene TriggerEvent;
public int sceneManager;
public float speed = 30;
void Start()
{
TriggerEvent = RightSideScene.GetComponent(TriggerEvent)();
// Initial Velocity
GetComponent<Rigidbody2D>().velocity = Vector2.right * speed;
}
private void TimeScale()
{
throw new NotImplementedException();
}
float hitFactor(Vector2 ballPos, Vector2 racketPos,
float racketHeight)
{
// ascii art:
// || 1 <- at the top of the racket
// ||
// || 0 <- at the middle of the racket
// ||
// || -1 <- at the bottom of the racket
return (ballPos.y - racketPos.y) / racketHeight;
}
void OnCollisionEnter2D(Collision2D col)
{
// Note: 'col' holds the collision information. If the
// Ball collided with a racket, then:
// col.gameObject is the racket
// col.transform.position is the racket's position
// col.collider is the racket's collider
// Hit the left Racket?
if (col.gameObject.name == "RacketLeft")
{
// Calculate hit Factor
float y = hitFactor(transform.position,
col.transform.position,
col.collider.bounds.size.y);
// Calculate direction, make length=1 via .normalized
Vector2 dir = new Vector2(1, y).normalized;
// Set Velocity with dir * speed
GetComponent<Rigidbody2D>().velocity = dir * speed;
}
// Hit the right Racket?
if (col.gameObject.name == "RacketRight")
{
// Calculate hit Factor
float y = hitFactor(transform.position,
col.transform.position,
col.collider.bounds.size.y);
// Calculate direction, make length=1 via .normalized
Vector2 dir = new Vector2(-1, y).normalized;
// Set Velocity with dir * speed
GetComponent<Rigidbody2D>().velocity = dir * speed;
}
}
public void Trigger(Collider2D other)
{
if (other.tag == "WallLeft")
{
RightSideScene.TriggerEvent(sceneManager);
{
}
}
}
}
This is the script for RightSideScene
For Your Information, I get no errors what so ever
public bool startedLoad;
public void TriggerEvent (Collider2D other)
{
if (other.gameObject.tag == "Ball")
{
SceneManager.LoadScene("RightSide Scene");
startedLoad = true;
}
}
}
So what I am trying to do is when the 'Ball' hits the 'WallLeft' (I did do a type for the Loading of the Scene ;)) it loads the scene RightSideScene (aka the LeftSideScene, typos for the win)