Hello everyone,
I was here in this forum a while ago, and I’m learning Software Engineering at the moment.
I’m using Unity3d in my spare time.
I created a game long before I started my degree, and while I’m working on it, I’ve learnt a lot of new things in coding, especially Design Pattern called “Business Layers” pattern.
Now I want to convert all my scripts that were in Javascript to C#.
I’ve created a Jet that flies, and I want to implement him my physics, through my C# solution, and not through JS. I’m creating a new “Unity C#” file in order to convert everything.
And here is the error I encountered, there is no namespace in the C# unity file, and somehow I can’t create a new “FactoryPhysics” object or even use Inheritance.
Then how to solve this issue? how can I implement my Factory into the “Unity C#” file?
Edited question.
Here is the issue, I think it is explained enough:
This is the Factory script, which creates a singleton for my implemented interface.
using System;
using System.Collections;
namespace Physics
{
public class FactoryPhysics
{
static Physics.iPhysics p;
public static Physics.iPhysics getJetPhysics()
{
if(p == null)
p = new Physics.Physics_imp();
return p;
}
}
}
Now here is the Unity C# script:
using System;
using UnityEngine;
using System.Collections;
FactoryPhysics p = getJetPhysics(); //This line is the problem, explained below
public class Jet : MonoBehaviour
{
// Use this for initialization
void Start ()
{
rigidbody.AddRelativeForce(Vector3.forward * 200, ForceMode.Impulse);
}
// Update is called once per frame
void Update ()
{
}
void FixedUpdate()
{
}
}
The compiler says “Parser Error: Unexpected Symbol, FactoryPhysics.”
Although all the scripts are in the same solution.